-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
79 lines (67 loc) · 1.94 KB
/
index.android.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
/**
* @Aspsine
* https://github.com/Aspsine/ReactMarvel
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
BackAndroid,
View,
Text,
Navigator
} from 'react-native';
import SplashScene from './react_native/src/main/js/scene/SplashScene.js';
import FeedScene from './react_native/src/main/js/scene/feed/FeedScene.js';
import AboutScene from './react_native/src/main/js/scene/AboutScene.js';
import DetailScene from './react_native/src/main/js/scene/DetailScene.js';
class Marvel extends Component {
constructor(props) {
super(props);
this.handleBack = this.handleBack.bind(this);
this.renderScene = this.renderScene.bind(this);
}
renderScene(route, navigator) {
this.navigator = navigator;
if (route.name == 'splash') {
return (<SplashScene navigator={navigator} />);
}else if(route.name == 'feed'){
return (<FeedScene navigator={navigator} />);
}else if(route.name == 'about'){
return (<AboutScene navigator={navigator} />);
}else if (route.name == 'detail') {
return (<DetailScene navigator={navigator} character={route.character}/>);
}
}
componentDidMount() {
BackAndroid.addEventListener('hardwareBackPress', this.handleBack);
}
ComponentWillUnmount() {
BackAndroid.removeEventListener('hardwareBackPress', this.handleBack);
}
handleBack() {
if (this.navigator && this.navigator.getCurrentRoutes().length > 1 ) {
this.navigator.pop();
return true;
}
return false;
}
render() {
var initialRoute = {name:'splash'}
return (
<Navigator
style={styles.navigator}
initialRoute={initialRoute}
configureScence={(route, routeStack) => Navigator.SceneConfigs.FadeAndroid}
renderScene={this.renderScene}
/>
)
}
}
const styles = StyleSheet.create({
navigator: {
flex: 1,
backgroundColor: '#FFFFFF',
},
});
AppRegistry.registerComponent('Marvel', () => Marvel);