-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathIndexList.js
128 lines (118 loc) · 2.84 KB
/
IndexList.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
125
126
127
128
'use strict';
var React = require('react-native');
var {
Image,
StyleSheet,
Text,
View,
ListView,
Dimensions,
TouchableOpacity,
ToastAndroid,
ToolbarAndroid,
} = React;
var deviceWidth = Dimensions.get('window').width; //todo 没有绑定屏幕旋转事件
var API_HOME_URL = 'http://123.57.6.75:8080/source/production/list/';
var lastPage = 1;
var dataList = [];
var IndexList = React.createClass({
getInitialState() {
var dataSource = new ListView.DataSource({
rowHasChanged: (row1, row2) => row1.id !== row2.id,
});
return {
isLoading: false,
dataSource: dataSource,
};
},
componentDidMount() {
this.fetchStories(lastPage);
},
fetchStories(page) {
lastPage = parseInt(page) < 0 ? lastPage : parseInt(page);
this.setState({
isLoading: true,
});
fetch(API_HOME_URL+ lastPage + "/7?type=0&cate=0")
.then((response) => response.json())
.then((responseData) => {
if(responseData.status){
dataList = dataList.concat(responseData.data);
this.setState({
isLoading: false,
dataSource: this.state.dataSource.cloneWithRows(dataList)
});
}else{
console.error(responseData.msg);
}
})
.catch((error) => {
console.error(error);
})
.done();
},
renderRow(rowData: string, sectionID: number, rowID: number){
return (
<TouchableOpacity onPress={() => this._pressRow(rowData)}>
<View style={styles.listRow}>
{rowData.creator.face?
<Image
source={{uri: rowData.creator.face}}
style={styles.cellImage}/>
:
<Image source={require('image!account_avatar')} style={styles.cellImage}/>
}
<View style={styles.info}>
<Text style={styles.text}>{rowData.content}...</Text>
</View>
</View>
</TouchableOpacity>
);
},
render(){
return (
<ListView
onEndReached={()=>{this.fetchStories(lastPage+1);ToastAndroid.show("加载中", ToastAndroid.SHORT);}}
dataSource={this.state.dataSource}
renderRow={this.renderRow} />
);
},
_pressRow(data){
this.props.navigator.push({
title: data.title,
name: 'article',
article: data,
});
},
});
var styles = StyleSheet.create({
listRow: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: 'white',
padding: 10,
marginLeft: 5,
marginRight: 10,
marginVertical: 5,
borderColor: '#dddddd',
borderStyle: null,
borderWidth: 0.5,
borderRadius: 2,
},
cellImage: {
height: 50,
marginRight: 15,
width: 50,
borderRadius: 100,
},
info: {
width: 200,
justifyContent: 'flex-start',
},
text: {
fontSize: 12,
}
});
module.exports = IndexList;