-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
98 lines (90 loc) · 2.25 KB
/
App.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
import React from 'react'
import { observer } from 'mobx-react'
import {
StyleSheet, View
} from 'react-native'
import { enableLogging } from 'mobx-logger'
import { createSwitchNavigator, createStackNavigator, createAppContainer } from 'react-navigation'
import Home from 'screens/Home'
import Detail from 'screens/Detail'
import LoginScreen from 'screens/Login'
import UserStore from 'mobxStore/UserStore'
import NaviStore from 'mobxStore/NaviStore'
/** ------------------------------------------*
* Activities:
* 1. BackHandler
* 2. checkUpdate
* 3. configPushNotification
* 4. AppState (background, inactive, active)
* ------------------------------------------- */
/** ------------------------------------------*
* Group Code: Debug
* ------------------------------------------- */
console.disableYellowBox = true
const config = {
predicate: () => __DEV__,
action: true,
reaction: true,
transaction: true,
compute: true
}
enableLogging(config)
/** ------------------------------------------*
* Group Code: Navigation
* ------------------------------------------- */
const stack1 = createStackNavigator(
{
Home: Home,
Detail: Detail
}
)
const SwitchNavigator = (isLogin) => createSwitchNavigator(
{
LoggedOut: {
screen: LoginScreen
},
LoggedIn: {
screen: stack1
}
},
{
initialRouteName: isLogin ? 'LoggedIn' : 'LoggedOut'
}
)
const getRootNavigation = (isLogin) => createAppContainer(SwitchNavigator(isLogin))
// import PropTypes from 'prop-types'
@observer
class App extends React.PureComponent {
constructor (props) {
super(props)
this.state = ({
isLogin: false
})
}
async componentDidMount () {
const isLogin = await UserStore.getLogin()
this.setState({ isLogin })
}
render () {
const RootNavigator = getRootNavigation(this.state.isLogin)
return (
<View style={styles.container}>
<RootNavigator
onNavigationStateChange={(prev, next) => NaviStore.onNavigationStateChange(prev, next)}
// eslint-disable-next-line no-return-assign
ref={nav => NaviStore.navigator = nav}
/>
</View>
)
}
}
export default App
App.defaultProps = {
}
App.propTypes = {
}
const styles = StyleSheet.create({
container: {
flex: 1
}
})