-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageList.js
134 lines (120 loc) · 3.15 KB
/
ImageList.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
129
130
131
132
133
134
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {FlatList, Image, StyleSheet, View} from 'react-native';
// const instructions = Platform.select({
// ios: 'Press Cmd+R to reload,\n' +
// 'Cmd+D or shake for dev menu',
// android: 'Double tap R on your keyboard to reload,\n' +
// 'Shake or press menu button for dev menu',
// });
class GanHuoItem extends Component{
constructor(props){
super(props)
}
render(){
const { navigate } = this.props.nav;
return(
<View>
<Image source={{uri: this.props.ganhuoItem.url,cache:'force-cache'}}
style={{width: 400, height: 400}} />
</View>
)
}
}
export default class ImageList extends Component{
currentPage=1;
constructor(props){
super(props)
this.state={ganhuoData:[]};
}
render() {
return (
<View style={styles.container}>
<FlatList
style={styles.list}
data={this.state.ganhuoData}
renderItem={({item})=><GanHuoItem ganhuoItem={item} nav={this.props.navigation}/>}
onRefresh={
this.refreshing
}
refreshing={false}
onEndReached={
this._onload
}
ItemSeparatorComponent={this._separator}
numColumns='1'
/>
</View>
);
}
//刷新
refreshing=()=>{
this.currentPage=1;
this.setState(previousState=>{
return {
ganhuoData:[]
}
});
this.getGanHuoData();
}
//加载更多
_onload=()=>{
this.getGanHuoData();
}
//分割线组件
_separator = () => {
return <View style={{height:2,backgroundColor:'lightgrey'}}/>;
}
componentDidMount(){
this.getGanHuoData();
}
getGanHuoData() {
let that=this;
return fetch('http://gank.io/api/data/'+this.props.type+'/10/'+this.currentPage++)
.then((response) =>response.json())
.then((responseJson) => {
console.log('请求成功');
temp=that.state.ganhuoData.concat(responseJson.results);
that.setState(previousState=>{
return {
ganhuoData:temp
}
});
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
}
const styles = StyleSheet.create({
item_container:{
backgroundColor:'white',
padding:20,
},
text_title:{
color:'black',
fontSize:20
},
text_author:{
color:'grey',
fontSize:16,
marginTop:10
},
author:{
flex:1,
alignItems:'flex-end'
},
line:{
backgroundColor:'lightgrey',
height:1,
marginTop:10
},
list:{
marginTop:50
}
});