Skip to content

Commit a3b1167

Browse files
committed
Highlight if nodes are opened or not
1 parent a443acc commit a3b1167

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed

NodeView.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export default class NodeView extends React.PureComponent<Props, State> {
2929

3030
componentWillMount = () => {
3131
this.setState({
32-
node: this.props.node,
32+
node: {
33+
opened: false,
34+
...this.props.node,
35+
},
3336
})
3437
}
3538

examples/HomeScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const options = [
88
title: 'Custom Node Example',
99
},
1010
{
11-
screen: 'NodeStatusChangeExample',
12-
title: 'Node Status Change',
11+
screen: 'StateChangeNodeExample',
12+
title: 'Opened Nodes Change',
1313
},
1414
]
1515

examples/StateChangeNodeExample.js

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

examples/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import React, {Component} from 'react'
22
import {AppRegistry} from 'react-native'
33
import CustomNodeExample from './CustomNodeExample'
4+
import StateChangeNodeExample from './StateChangeNodeExample'
5+
46
import HomeScreen from './HomeScreen'
57

68
import {StackNavigator} from 'react-navigation'
79

810
const SimpleApp = StackNavigator({
911
Home: {screen: HomeScreen},
1012
CustomNodeExample: {screen: CustomNodeExample},
13+
StateChangeNodeExample: {screen: StateChangeNodeExample},
1114
})
1215

1316
AppRegistry.registerComponent('example', () => SimpleApp)

0 commit comments

Comments
 (0)