Skip to content

Commit b223eb0

Browse files
author
Javier Morant
authored
Update content dinamically (#53)
* Added dynamiccontent example * Update content * Ingore dist folder * Ignore .tsx files * Move source folder * Fix issue * Fix typescript issue * Fix tests issues * Generated more tests * Fix tslint issue * ignore source * remove unnecessary method
1 parent 6182a28 commit b223eb0

18 files changed

+763
-109
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ lib/
77

88
# Jest
99
#
10-
.jest/
10+
.jest/
11+
12+
dist/

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
examples
22
flow-typed
3-
node_modules
3+
node_modules
4+
src

examples/DynamicContentExample.js

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
Button,
12+
} from 'react-native'
13+
import NestedListView from 'react-native-nested-listview'
14+
15+
const data = [
16+
{
17+
name: 'Books Genders',
18+
descendants: [
19+
{
20+
name: 'Adventure',
21+
},
22+
{
23+
name: 'Romance',
24+
},
25+
],
26+
},
27+
{
28+
name: 'Movies',
29+
descendants: [
30+
{
31+
name: 'Drama',
32+
},
33+
{
34+
name: 'Action',
35+
},
36+
],
37+
},
38+
{
39+
name: 'Technology',
40+
descendants: [
41+
{name: 'Phones', descendants: [{name: 'Samsung'}, {name: 'iPhone'}]},
42+
],
43+
},
44+
]
45+
46+
const data2 = [
47+
{
48+
name: 'Music',
49+
descendants: [
50+
{
51+
name: 'Rock',
52+
},
53+
{
54+
name: 'Heavy Metal',
55+
},
56+
{
57+
name: 'Pop',
58+
},
59+
],
60+
},
61+
{
62+
name: 'Food',
63+
descendants: [
64+
{
65+
name: 'Dairy',
66+
},
67+
{
68+
name: 'Sweet',
69+
descendants: [
70+
{
71+
name: 'Chocolat',
72+
},
73+
{
74+
name: 'Sugar',
75+
},
76+
{
77+
name: 'Biscuits',
78+
},
79+
],
80+
},
81+
],
82+
},
83+
{
84+
name: 'Technology',
85+
descendants: [{name: 'Laptop', descendants: [{name: 'Pc', name: 'Mac'}]}],
86+
},
87+
]
88+
89+
const styles = StyleSheet.create({
90+
container: {flex: 1, backgroundColor: 'rgb(255, 255, 255)', padding: 15},
91+
node: {
92+
flex: 1,
93+
padding: 10,
94+
borderWidth: 1,
95+
borderColor: 'rgb(0, 0, 0)',
96+
},
97+
})
98+
export default class ExampleApp extends React.Component<Props, State> {
99+
nestedListView: any
100+
101+
state = {
102+
dataSource: 'data',
103+
}
104+
105+
renderNode = (node: Object, level: number) => {
106+
const paddingLeft = (level + 1) * 30
107+
108+
return (
109+
<View style={[styles.node, {backgroundColor: 'white', paddingLeft}]}>
110+
<Text>{node.name}</Text>
111+
</View>
112+
)
113+
}
114+
115+
getChildrenName = (node: Object) => {
116+
return 'descendants'
117+
}
118+
onPressUpdate = () => {
119+
if (this.state.dataSource === 'data') {
120+
this.setState({
121+
dataSource: 'data2',
122+
})
123+
} else {
124+
this.setState({
125+
dataSource: 'data',
126+
})
127+
}
128+
}
129+
130+
render = () => {
131+
return (
132+
<View style={styles.container}>
133+
<View style={{margin: 10}}>
134+
<Button onPress={this.onPressUpdate} title="Update Content" />
135+
</View>
136+
<NestedListView
137+
data={this.state.dataSource === 'data' ? data : data2}
138+
getChildrenName={this.getChildrenName}
139+
onNodePressed={this.onNodePressed}
140+
renderNode={this.renderNode}
141+
/>
142+
</View>
143+
)
144+
}
145+
}

examples/HomeScreen.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ const options = [
1919
screen: 'NestedRowExample',
2020
title: 'NestedRow',
2121
},
22+
{
23+
screen: 'DynamicContentExample',
24+
title: 'Dynamic Content',
25+
},
2226
]
2327

2428
export default class HomeScreen extends React.Component {
@@ -38,8 +42,7 @@ export default class HomeScreen extends React.Component {
3842
borderWidth: 1,
3943
borderColor: 'rgb(0, 0, 0)',
4044
}}
41-
onPress={() => this.props.navigation.navigate(option.screen)}
42-
>
45+
onPress={() => this.props.navigation.navigate(option.screen)}>
4346
<Text style={{color: 'rgb(0, 0, 0)'}}>{option.title}</Text>
4447
</TouchableOpacity>
4548
))}

examples/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CustomNodeExample from './CustomNodeExample'
44
import StateChangeNodeExample from './StateChangeNodeExample'
55
import ErrorMessageExample from './ErrorMessageExample'
66
import NestedRowExample from './NestedRowExample'
7+
import DynamicContentExample from './DynamicContentExample'
78

89
import HomeScreen from './HomeScreen'
910

@@ -15,6 +16,7 @@ const SimpleApp = StackNavigator({
1516
StateChangeNodeExample: {screen: StateChangeNodeExample},
1617
ErrorMessageExample: {screen: ErrorMessageExample},
1718
NestedRowExample: {screen: NestedRowExample},
19+
DynamicContentExample: {screen: DynamicContentExample},
1820
})
1921

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

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"react": "16.0.0",
1414
"react-native": "~0.49.3",
1515
"react-native-nested-listview": "file:../",
16-
"react-navigation": "^1.0.0-beta.13",
16+
"react-navigation": "1.5.8",
1717
"shortid": "^2.2.8"
1818
},
1919
"devDependencies": {

0 commit comments

Comments
 (0)