-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApodReactNativeBaseComponent.js
118 lines (108 loc) · 2.6 KB
/
ApodReactNativeBaseComponent.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
'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
ActivityIndicatorIOS,
ScrollView,
StatusBarIOS,
LayoutAnimation,
Navigator,
} = React;
var xmldoc = require('xmldoc');
var Dimensions = require('Dimensions');
var Apod = require('./ApodComponent');
var ApodList = require('./ApodsListComponent');
var getApods = require('./getApods');
var ApodReactNative = React.createClass({
getInitialState: function() {
return {
loaded: false,
};
},
componentDidMount: function() {
getApods().then(apods => {
this.setState({
items: apods,
loaded: true,
selectedIndex: 0,
}).done();
});
},
renderScene: function(route, navigator) {
return route.renderer(route, navigator);
},
renderLoading: function() {
return (
<View style={styles.container}>
<ActivityIndicatorIOS/>
<Text>Loading...</Text>
</View>
);
},
render: function() {
var self = this;
if (!this.state.loaded) {
return this.renderLoading();
}
var ROUTES = [
{
name: 'Apods',
renderer: (route, navigator, onRef) => {
return(
<ApodList
items={this.state.items}
onItemSelected={(index) => {
this.setState({ selectedIndex: index });
navigator.jumpTo(ROUTES[1]);
}}/>
);
},
onWillFocus: () => {
StatusBarIOS.setHidden(false, 1);
StatusBarIOS.setStyle(0, true);
},
},
{
name: 'Selected Apod',
renderer: (route, navigator, onRef) => {
return (<Apod item={this.state.items[this.state.selectedIndex]} />);
},
sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
}
];
return (
<View style={{flex:1,backgroundColor:'#111111',}}>
<Navigator
renderScene={this.renderScene}
initialRoute={ROUTES[1]}
initialRouteStack={ROUTES}
configureScene={route => {
return route.sceneConfig || Navigator.SceneConfigs.FloatFromRight;
}}
onWillFocus={route => {
if (route.onWillFocus) {
route.onWillFocus();
}
}}
onDidFocus={(route) => {
if (route.onDidFocus) {
route.onDidFocus();
}
}}
/>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#000000',
},
});
module.exports = ApodReactNative;