forked from dsibiski/react-native-hybrid-app-examples
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimpleList.js
84 lines (73 loc) · 1.88 KB
/
SimpleList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
var React = require('react-native');
var {
Text,
View,
TouchableHighlight,
ListView,
} = React;
class SimpleList extends React.Component {
constructor(props) {
super(props);
var dataSource = new ListView.DataSource(
{rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: dataSource.cloneWithRows(this.props.data)
};
this._renderRow = this._renderRow.bind(this);
this._rowPressed = this._rowPressed.bind(this);
}
_rowPressed(row) {
if (this.props.rowPressed) {
this.props.rowPressed(row);
}
console.log(row);
}
_renderRow(rowData, sectionID, rowID) {
return (
<TouchableHighlight
onPress={() => this._rowPressed(
this.props.data[rowID])
}
underlayColor='#f3f3f3'>
<View style={styles.container}>
<View style={styles.rowContainer}>
<Text style={styles.name}>{rowData}</Text>
</View>
<View style={styles.separator}/>
</View>
</TouchableHighlight>
);
}
render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow}
initialListSize={20}
/>
);
}
}
SimpleList.propTypes = {
data: React.PropTypes.array.isRequired,
};
var styles = React.StyleSheet.create({
separator: {
height: 1,
backgroundColor: '#dddde0'
},
name: {
fontSize: 19,
color: '#000'
},
container: {
marginLeft: 15
},
rowContainer: {
flexDirection: 'row',
padding: 10,
paddingLeft: 0
}
});
module.exports = SimpleList;