Skip to content

Commit fc79c1d

Browse files
committed
First version working
1 parent 035fe53 commit fc79c1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+10260
-11
lines changed

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
example
2+
3+
node_modules

NodeView.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* @flow */
2+
3+
import React from 'react'
4+
import {TouchableOpacity, View} from 'react-native'
5+
6+
const NodeView = ({
7+
getChildren,
8+
node,
9+
renderNode,
10+
renderChildrenNode,
11+
onLayout,
12+
onNodePressed,
13+
}: {
14+
getChildren: Function,
15+
node: any,
16+
nodeStyle?: any,
17+
onLayout?: Function,
18+
onNodePressed: Function,
19+
renderNode: Function,
20+
renderChildrenNode: Function,
21+
}) => {
22+
const children = getChildren(node)
23+
24+
return (
25+
<View onLayout={onLayout}>
26+
<TouchableOpacity onPress={() => onNodePressed(node)}>
27+
{renderNode()}
28+
</TouchableOpacity>
29+
{node.opened && children
30+
? <View>
31+
{children.map(renderChildrenNode)}
32+
</View>
33+
: null}
34+
</View>
35+
)
36+
}
37+
38+
export default NodeView

example/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-native"]
3+
}

example/.buckconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

example/.flowconfig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore unexpected extra "@providesModule"
9+
.*/node_modules/.*/node_modules/fbjs/.*
10+
11+
; Ignore duplicate module providers
12+
; For RN Apps installed via npm, "Libraries" folder is inside
13+
; "node_modules/react-native" but in the source repo it is in the root
14+
.*/Libraries/react-native/React.js
15+
.*/Libraries/react-native/ReactNative.js
16+
17+
[include]
18+
19+
[libs]
20+
node_modules/react-native/Libraries/react-native/react-native-interface.js
21+
node_modules/react-native/flow
22+
flow/
23+
24+
[options]
25+
emoji=true
26+
27+
module.system=haste
28+
29+
munge_underscores=true
30+
31+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
32+
33+
suppress_type=$FlowIssue
34+
suppress_type=$FlowFixMe
35+
suppress_type=$FixMe
36+
37+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
38+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
39+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
40+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
41+
42+
unsafe.enable_getters_and_setters=true
43+
44+
[version]
45+
^0.49.1

example/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

example/.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
33+
# node.js
34+
#
35+
node_modules/
36+
npm-debug.log
37+
yarn-error.log
38+
39+
# BUCK
40+
buck-out/
41+
\.buckd/
42+
*.keystore
43+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
50+
51+
fastlane/report.xml
52+
fastlane/Preview.html
53+
fastlane/screenshots

example/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

example/ExampleApp.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* @flow */
2+
3+
import React from 'react'
4+
import {StyleSheet, Text, View} from 'react-native'
5+
import NestedListView from './nestedListView'
6+
7+
const styles = StyleSheet.create({})
8+
9+
const generateXNumItems = (numItems, prefix) => {
10+
const items = []
11+
12+
for (i = 0; i < numItems; i++) {
13+
items.push({
14+
name: `${prefix}.${i}`,
15+
})
16+
}
17+
18+
return items
19+
}
20+
21+
const data = [
22+
{
23+
name: 'Item level 1.1',
24+
items: generateXNumItems(100, 'Item level 1.1')
25+
},
26+
{
27+
name: 'Item level 1.2',
28+
items: [
29+
{
30+
name: 'Item level 1.2.1',
31+
},
32+
{
33+
name: 'Item level 1.2.2',
34+
children: generateXNumItems(1000, 'Item level 1.2.2')
35+
},
36+
],
37+
},
38+
{
39+
name: 'Item level 1.3',
40+
items: generateXNumItems(1000, 'Item level 1.3'),
41+
},
42+
]
43+
44+
export default class ExampleApp extends React.Component {
45+
nestedListView: any
46+
47+
renderNode = (node: Object, level: string) => {
48+
const paddingLeft = (level + 1) * 10
49+
return (
50+
<View style={{flex: 1, padding: 10, paddingLeft, borderWidth: 1, borderColor: 'rgb(0, 0, 0)'}}>
51+
<Text>{node.name}</Text>
52+
</View>
53+
)
54+
}
55+
56+
onNodePressed = (node: any) => {
57+
// alert(JSON.stringify(node))
58+
}
59+
60+
getChildrenName = (node: Object) => {
61+
if(node.name === 'Item level 1.2.2') {
62+
return 'children'
63+
}
64+
65+
return 'items'
66+
}
67+
68+
render = () => {
69+
return (
70+
<View style={{flex: 1, backgroundColor: 'rgb(255, 255, 255)', padding: 10}}>
71+
<NestedListView
72+
data={data}
73+
getChildrenName={this.getChildrenName}
74+
onNodePressed={this.onNodePressed}
75+
ref={ref => {
76+
this.nestedListView = ref
77+
}}
78+
renderNode={this.renderNode}
79+
style={{padding: 10}}
80+
/>
81+
</View>
82+
)
83+
}
84+
}

example/__tests__/index.android.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import Index from '../index.android.js';
4+
5+
// Note: test renderer must be required after react-native.
6+
import renderer from 'react-test-renderer';
7+
8+
it('renders correctly', () => {
9+
const tree = renderer.create(
10+
<Index />
11+
);
12+
});

0 commit comments

Comments
 (0)