-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.android.js
More file actions
75 lines (71 loc) · 1.62 KB
/
Copy pathindex.android.js
File metadata and controls
75 lines (71 loc) · 1.62 KB
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var Loading = require('./app/components/Loading');
var Post = require('./app/components/Post');
var ScrollGallery = require('./app/components/ScrollGallery');
var api = require('./app/utils/api');
var {
AppRegistry,
StyleSheet,
View,
} = React;
var Imgur = React.createClass({
selectImage: function(image) {
this.setState({
image: image,
})
},
loadGallery: function() {
this.setState({
count: this.state.count+10
})
},
getInitialState: function() {
return {
image: {},
gallery: [],
loaded: false,
count: 10,
};
},
componentDidMount: function() {
api.getGallery().then(function(res) {
if (res.success) {
var gallery = res.data.filter(function(post) {
return !post.is_album && !post.animated;
})
this.setState({
image: gallery[0],
gallery: gallery,
loaded: true,
});
}
}.bind(this))
},
render: function() {
if (!this.state.loaded) {
return (<Loading />);
}
var gallery = this.state.gallery.slice(0, this.state.count);
return (
<View style={styles.container}>
<Post image={this.state.image}/>
<ScrollGallery
gallery={gallery}
selectImage={this.selectImage}
loadGallery={this.loadGallery} />
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#2B2B2B',
},
});
AppRegistry.registerComponent('Imgur', () => Imgur);