-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListViewTest.js
More file actions
163 lines (156 loc) · 4.38 KB
/
ListViewTest.js
File metadata and controls
163 lines (156 loc) · 4.38 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Created by penn on 2016/12/19.
*/
import React, {Component} from 'react';
import {
StyleSheet,
Text,
Navigator,
Image,
View,
ListView,
RefreshControl,
TouchableOpacity,
} from 'react-native';
import Toast, {DURATION} from 'react-native-easy-toast'
import NavigationBar from './js/common/NavigationBar'
var data = {
"result": [
{
"email": "f.lee@taylor.edu",
"fullName": "张三张三张三张三"
},
{
"email": "g.jackson@hall.net",
"fullName": "张三张三张三张三张三"
},
{
"email": "l.hall@rodriguez.com",
"fullName": "张三张三张三张三"
},
{
"email": "q.lopez@davis.io",
"fullName": "张三张三张三张三"
},
{
"email": "c.gonzalez@perez.net",
"fullName": "张三张三张三"
},
{
"email": "a.johnson@williams.net",
"fullName": "张三张三"
},
{
"email": "i.anderson@lopez.edu",
"fullName": "张三张三"
},
{
"email": "r.lee@davis.org",
"fullName": "张三张三"
},
{
"email": "o.young@lee.edu",
"fullName": "张三张三张三张三张三"
},
{
"email": "j.wilson@williams.org",
"fullName": "张三张三张三张三张三"
},
{
"email": "z.walker@jackson.io",
"fullName": "张三张三"
},
{
"email": "j.martinez@brown.gov",
"fullName": "张三张三张三张三"
},
{
"email": "y.martin@lewis.io",
"fullName": "张三张三张三张三"
},
{
"email": "w.taylor@gonzalez.org",
"fullName": "张三张三"
},
{
"email": "j.thomas@garcia.org",
"fullName": "张三张三张三张三"
}
],
"statusCode": 0
};
export default class ListViewTest extends Component {
constructor(props) {
super(props);
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2)=> {
r1 !== r2
}
});
this.state = {
dataSource: ds.cloneWithRows(data.result),
isLoading: true
}
}
onReload() {
setTimeout(()=> {
this.setState({
isLoading: false
})
}, 2000);
}
renderRow(rowData) {
return (
<View>
<TouchableOpacity
onPress={()=>{
this.toast.show('你单击了,'+rowData.fullName,DURATION.LENGTH_LONG);
}}>
<Text style={styles.item}>
{rowData.fullName}
</Text>
<Text style={styles.item}>
{rowData.email}
</Text>
</TouchableOpacity>
</View>
)
}
renderFooter() {
return <View>
<Image
style={{width: 300, height: 100}}
source={{uri: 'https://images.gr-assets.com/hostedimages/1406479536ra/10555627.gif'}}/>
</View>
}
renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
return <View key={rowID} style={{height: 1, backgroundColor: 'black'}}></View>
}
render() {
return (
<View>
<NavigationBar
title="ListView使用"/>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData)=>this.renderRow(rowData)}
refreshControl={
<RefreshControl
refreshing={this.state.isLoading}
onRefresh={this.onReload()}
/>
}
renderFooter={()=>this.renderFooter()}
renderSeparator={(sectionID, rowID, adjacentRowHighlighted)=>this.renderSeparator(sectionID, rowID, adjacentRowHighlighted)}
></ListView>
<Toast ref={(toast)=>{this.toast=toast}}/>
</View>
)
}
}
const styles = StyleSheet.create({
item: {
height: 40,
padding: 5
}
})