forked from invertase/react-native-material-design-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
91 lines (80 loc) · 2.33 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
80
81
82
83
84
85
86
87
88
89
90
91
import React, { AppRegistry, Component, Navigator, DrawerLayoutAndroid, ScrollView, View, Text } from 'react-native';
import Navigate from './src/utils/Navigate';
import { Toolbar } from './src/components';
import Navigation from './src/scenes/Navigation';
import Welcome from './src/scenes/Welcome';
class Application extends Component {
static childContextTypes = {
drawer: React.PropTypes.object,
navigator: React.PropTypes.object
};
constructor(props) {
super(props);
this.state = {
drawer: null,
navigator: null
};
}
getChildContext = () => {
return {
drawer: this.state.drawer,
navigator: this.state.navigator
}
};
setDrawer = (drawer) => {
this.setState({
drawer
});
};
setNavigator = (navigator) => {
this.setState({
navigator: new Navigate(navigator)
});
};
render() {
const { drawer, navigator } = this.state;
const navView = React.createElement(Navigation);
return (
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
renderNavigationView={() => {
if (drawer && navigator) {
return navView;
}
return null;
}}
ref={(drawer) => { !this.state.drawer ? this.setDrawer(drawer) : null }}
>
{drawer &&
<Navigator
initialRoute={Navigate.getInitialRoute()}
navigationBar={<Toolbar onIconPress={drawer.openDrawer} />}
configureScene={() => {
return Navigator.SceneConfigs.FadeAndroid;
}}
ref={(navigator) => { !this.state.navigator ? this.setNavigator(navigator) : null }}
renderScene={(route) => {
if (this.state.navigator && route.component) {
return (
<View
style={styles.scene}
showsVerticalScrollIndicator={false}>
<route.component title={route.title} path={route.path} {...route.props} />
</View>
);
}
}}
/>
}
</DrawerLayoutAndroid>
);
}
}
AppRegistry.registerComponent('DemoApp', () => Application);
const styles = {
scene: {
flex: 1,
marginTop: 56
}
};