-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListViewTest.js
More file actions
141 lines (138 loc) · 3.34 KB
/
ListViewTest.js
File metadata and controls
141 lines (138 loc) · 3.34 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import React, {Component} from 'react'
import {
View,
Text,
StyleSheet,
TouchableOpacity,
Image,
ListView,
RefreshControl
} from 'react-native'
import NavigationBar from './NavigationBar'
import Toast, {DURATION} from 'react-native-easy-toast'
var data = {
'result': [
{
'email': 'laclys@126.com',
'fullName': 'Lac'
}, {
'email': 'sylcal@126.com',
'fullName': 'Cal'
}, {
'email': 'zyy@126.com',
'fullName': 'Zyy'
}, {
'email': '421084802@126.com',
'fullName': 'Zhang'
}, {
'email': 'yoyo@126.com',
'fullName': 'Yoyo'
}, {
'email': '123321@126.com',
'fullName': 'Bill'
}, {
'email': 'swonwhite@126.com',
'fullName': 'Swon'
}, {
'email': 'Mac@126.com',
'fullName': 'Mac'
}, {
'email': 'laclys1@126.com',
'fullName': 'Lac'
}, {
'email': 'sylcal1@126.com',
'fullName': 'Cal'
}, {
'email': 'zyy1@126.com',
'fullName': 'Zyy'
}, {
'email': '4210848021@126.com',
'fullName': 'Zhang'
}, {
'email': 'yoyo1@126.com',
'fullName': 'Yoyo'
}, {
'email': '1233211@126.com',
'fullName': 'Bill'
}, {
'email': 'swonwhite1@126.com',
'fullName': 'Swon'
}, {
'email': 'Mac1@126.com',
'fullName': 'Mac'
}
],
'statusCode': 0
}
export default class ListViewTest extends Component {
constructor (props) {
super(props)
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
})
this.state = {
dataScource: ds.cloneWithRows(data.result),
isLoading: true
}
this.onLoad()
}
renderRow (item, sectionID, rowID, highlightRow) {
return <View key={rowID} style={styles.row}>
<TouchableOpacity
onPress={() => {
this.toast.show('clicked!' + item.fullName, DURATION.LENGTH_LONG)
}}
>
<Text style={styles.text}>{item.fullName}</Text>
<Text style={styles.text}>{item.email}</Text>
</TouchableOpacity>
</View>
}
renderSeparator (sectionID, rowID, adjacentRowHighlighted) {
return <View key={rowID} style={styles.line} />
}
renderFooter () {
return <Image style={{width: 50, height: 50}} source={{uri: 'https://avatars1.githubusercontent.com/u/22010181?v=3&s=460'}} />
}
onLoad () {
setTimeout(() => {
this.setState({
isLoading: false
})
}, 2000)
}
render () {
return (
<View style={styles.container}>
<NavigationBar title={'ListViewTest'} />
<ListView
dataSource={this.state.dataScource}
renderRow={(item, sectionID, rowID, highlightRow) => this.renderRow(item, sectionID, rowID, highlightRow)}
renderSeparator={(sectionID, rowID, adjacentRowHighlighted) => this.renderSeparator(sectionID, rowID, adjacentRowHighlighted)}
renderFooter={() => this.renderFooter()}
refreshControl={<RefreshControl
refreshing={this.state.isLoading}
onRefresh={() => this.onLoad()}
/>}
/>
<Toast ref={toast => { this.toast = toast }} />
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white'
},
text: {
fontSize: 20
},
row: {
height: 50
},
line: {
height: 1,
backgroundColor: 'black'
}
})