-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListViewText.js
124 lines (118 loc) · 3.26 KB
/
ListViewText.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
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
/**
* Created by Administrator on 2017/3/15 0015.
*/
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet,
Image,
ListView,
TouchableOpacity,
RefreshControl
} from 'react-native';
import Girl from './Girl';
import NavigatorBar from './NavigatorBar';
import Toast, {DURATION} from 'react-native-easy-toast'
const data={
result:[
{
email:'haahhaha@1222.com',
fullname:'zhangsan'
},
{
email:'haahhaha@1222.com',
fullname:'zhangsan'
},
{
email:'haahhaha@1222.com',
fullname:'zhangsan'
},
{
email:'haahhaha@1222.com',
fullname:'zhangsan'
},
{
email:'haahhaha@1222.com',
fullname:'zhangsan'
}
]
}
export default class ListViewText 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
};
this.onLoad();
}
renderRow(item){
return <View style={styles.row}>
<TouchableOpacity
onPress={()=>{
this.toast.show('你单击了'+item.fullname,DURATION.LENGTH_LONG);
} }>
<Text style={styles.tips}>{item.email}</Text>
<Text style={styles.tips}>{item.fullname}</Text>
</TouchableOpacity>
</View>
}
renderFooter(){
return <Image style={{width:100, height:100} } source={require('./res/images/ic_polular.png')} />
}
renderSeparator(sectionID, rowID, adjacentRowHighlighted){
return <View key={rowID} style={styles.line}>
</View>
}
onLoad(){
setTimeout(()=>{
this.setState({
isLoading:false
})
},2000)
}
render(){
return (
<View style={styles.container} >
<NavigatorBar title='listview' justifyContent='center' backgroundColor='#02A682'/>
<ListView dataSource={this.state.dataSource}
renderRow={(item)=>this.renderRow(item)}
renderSeparator={(sectionID, rowID, adjacentRowHighlighted) =>this.renderSeparator(sectionID, rowID, adjacentRowHighlighted)}
renderFooter={()=>this.renderFooter()}
refreshControl={ <RefreshControl
refreshing={this.state.isLoading}
onRefresh={()=>this.onLoad()}
colors={['#ff0000', '#00ff00', '#0000ff']}
progressBackgroundColor="#ffff00"
/> }
/>
<Toast ref={toast=>{this.toast=toast}} />
</View>
)
}
}
const styles=StyleSheet.create({
container:{
flex:1,
backgroundColor:'gray'
},
text:{
fontSize:20
},
tips:{
fontSize:20,
color:'#37A'
},
row:{
height:50,
margin:5
},
line:{
height:1,
backgroundColor:'black'
}
})