-
Notifications
You must be signed in to change notification settings - Fork 3
/
EntryList.js
155 lines (149 loc) · 3.34 KB
/
EntryList.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var EntryDetail = require('./EntryDetail.js');
var {
StyleSheet,
Text,
View,
Image,
ListView,
TouchableHighlight,
ActivityIndicatorIOS
} = React;
var QIITA_REACTJS_ENTRY_URL = "https://qiita.com/api/v2/tags/reactjs/items";
var EntryList = React.createClass({
getInitialState: function(){
return(
{
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2
}),
isLoaded: false
}
);
},
componentDidMount: function(){
if(typeof this.props.entries !== 'undefined'){
console.log("I'm in search condition");
this.setState(
{
dataSource: this.state.dataSource.cloneWithRows(this.props.entries),
isLoaded: true
}
);
}else{
this.fetchData();
}
},
fetchData: function() {
fetch(QIITA_REACTJS_ENTRY_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
isLoaded: true
});
})
.done();
},
renderEntry: function(entry){
return(
<TouchableHighlight onPress={() => this.onPress(entry)}>
<View>
<View style={styles.container}>
<Image
source={{uri: entry.user.profile_image_url}}
style={styles.thumbnail}/>
<View style={styles.rightContainer}>
<Text style={styles.title}>{entry.title}</Text>
<Text style={styles.name}>{entry.user.id}</Text>
</View>
</View>
<View style={styles.separator}/>
</View>
</TouchableHighlight>
);
},
onPress: function(entry) {
this.props.navigator.push({
title: entry.title,
component: EntryDetail,
passProps: { url: entry.url }
})
},
viewLoadingData: function(){
return(
<View style={styles.activityIndicator}>
<ActivityIndicatorIOS
animating={1}
size={'large'}
/>
<View>
<Text style={styles.loadingMessage}>Please wait a second ...</Text>
</View>
</View>
);
},
render: function() {
if(this.state.isLoaded){
return(
<ListView
style={styles.listView}
dataSource={this.state.dataSource}
renderRow={this.renderEntry}
/>
);
}else{
return(
this.viewLoadingData()
);
};
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
thumbnail: {
width: 100,
height: 100,
marginRight: 10
},
rightContainer: {
flex: 1
},
title: {
fontSize: 20,
marginBottom: 8
},
name: {
color: '#656565'
},
separator: {
height: 1,
backgroundColor: '#DDDDDD',
},
listView: {
backgroundColor: '#F5FCFF'
},
activityIndicator: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
loadingMessage: {
flex: 1,
fontSize: 20,
color: '#656565',
}
});
module.exports = EntryList;