forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigation.js
More file actions
105 lines (89 loc) · 1.98 KB
/
Navigation.js
File metadata and controls
105 lines (89 loc) · 1.98 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
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
import React,{
Component,
PropTypes,
Navigator,
StyleSheet,
View,
Text,
Image,
Dimensions
} from 'react-native';
import * as Home from './Home';
import * as UtilsComponent from './Utils';
import Router from '../configs/Router';
import connectComponent from '../utils/connectComponent';
import config from '../configs';
const Utils = connectComponent(UtilsComponent);
const { height, width } = Dimensions.get('window');
const initialRoute = {
name: 'home',
index: 0,
component: connectComponent(Home),
id: 0
};
class Navigation extends Component {
constructor(props) {
super(props);
this.ids = [];
}
componentDidMount() {
this.navigator.navigationContext.addListener('didfocus', e => {
const { index, id } = e.data.route;
const haveFocused = this.ids.indexOf(id) > -1;
this[index] && this[index] && this[index].getWrappedInstance().componentDidFocus && this[index].getWrappedInstance().componentDidFocus(haveFocused);
!haveFocused && this.ids.push(id);
});
}
renderScene({ component, name, props, id, index }, navigator) {
this.router = this.router || new Router(navigator);
if (component) {
return React.createElement(component, {
...props,
ref: view => this[index] = view,
router: this.router,
route: {
name,
id,
index
}
});
}
}
configureScene(route) {
if (route.sceneConfig) {
return route.sceneConfig
}
return Navigator.SceneConfigs.FloatFromRight
}
render() {
return (
<Image
source={{ uri: config.bgImgUri }}
style={styles.bg}>
<Navigator
ref={view => this.navigator=view}
initialRoute={initialRoute}
configureScene={this.configureScene.bind(this)}
renderScene={this.renderScene.bind(this)}/>
<Utils/>
</Image>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
flexCenter: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
bg: {
flex: 1,
height,
width,
backgroundColor: 'transparent'
}
});
export default Navigation;