-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes
More file actions
65 lines (47 loc) · 1.63 KB
/
Copy pathnotes
File metadata and controls
65 lines (47 loc) · 1.63 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
import { StackNavigator } from 'react-navigation'
import * as stack from 'src/components/stack'
const Navigator = StackNavigator({
Landing: { screen: stack.Landing },
Home: { screen: stack.Home },
})
const initialState = Navigator.router.getStateForAction(
Navigator.router.getActionForPathAndParams('Landing')
)
export const reducer = (state = initialState, action) => {
const nextState = Navigator.router.getStateForAction(action, state)
return nextState || state
}
export default Navigator
helper methods that you dispatch
import { NavigationActions } from 'react-navigation'
export const to = (routeName, params = {}, action) =>
NavigationActions.navigate({ routeName, params, action })
export const back = () => NavigationActions.back()
import { addNavigationHelpers } from 'react-navigation'
class ScreenRoot extends Component {
constructor (props) {
super(props)
this.state = { isLoaded: false }
}
componentWillMount () {
BackHandler.addEventListener('hardwareBackPress', () => {
const index = this.props.nav.index
if (index !== (0 || 1)) return this.props.dispatch(navigator.navigate.back()) // this is just to prevent users to go back to landing page after login
return false
})
}
componentWillUnmount () {
BackHandler.removeEventListener('hardwareBackPress')
}
render () {
const { dispatch, nav, isLoading } = this.props
const { isLoaded } = this.state
if (!isLoaded) return <Splash />
else if (isLoading) return <Loading />
return (
<Root>
<Navigator navigation={addNavigationHelpers({ dispatch, state: nav })} />
</Root>
)
}
}