-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ios.js
119 lines (107 loc) · 2.3 KB
/
index.ios.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {
AppRegistry,
Component,
Image,
ListView,
StyleSheet,
Text,
View,
} from 'react-native';
var ACCESS_TOKEN = '';
var API_URL = 'https://api.instagram.com/v1';
var PARAMS = '/users/self/media/recent/?access_token=' + ACCESS_TOKEN;
var INSTAGRAM_REQUEST_URL = API_URL + PARAMS;
class react_ios_app extends Component {
constructor (props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2, }),
loaded: false,
};
}
componentDidMount() {
this.fetchData();
}
fetchData() {
fetch(INSTAGRAM_REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData.data),
loaded: true,
});
})
.done();
}
render() {
if (!this.state.loaded) {
return this.renderLoadingView();
}
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderMovie}
style={styles.listView}
/>
);
}
renderLoadingView() {
return (
<View style={styles.container}>
<Text>
Loading Photos ...
</Text>
</View>
);
}
renderMovie(feed) {
return (
<View style={styles.container}>
<Image
source={{uri: feed.images.thumbnail.url}}
style={styles.thumbnail}
/>
<View style={styles.rightContainer}>
<Text style={styles.title}>{feed.caption.text}</Text>
<Text style={styles.year}>{feed.caption.created_time}</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
thumbnail: {
width: 150,
height: 150,
},
rightContainer: {
flex: 1,
},
title: {
fontSize: 13,
marginBottom: 8,
textAlign: 'center',
},
year: {
fontSize: 13,
textAlign: 'center',
},
listView: {
paddingTop: 20,
backgroundColor: '#F5FCFF',
},
});
AppRegistry.registerComponent('react_ios_app', () => react_ios_app);