Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {
- StateUtils: NavigationStateUtils
- } = NavigationExperimental
- const initialState = {
- index: 0,
- key: 'root',
- routes: [{
- key: 'login',
- title: 'Login',
- component: Login
- }]
- }
- function navigationState (state = initialState, action) {
- switch(action.type) {
- case PUSH_ROUTE:
- if (state.routes[state.index].key === (action.route && action.route.key)) return state
- return NavigationStateUtils.push(state, action.route)
- case POP_ROUTE:
- if (state.index === 0 || state.routes.length === 1) return state
- return NavigationStateUtils.pop(state)
- default:
- return state
- }
- }
- handleBackAction() {
- if (this.props.navigation.index === 0) {
- return false
- }
- this.props.popRoute()
- return true
- }
- _handleNavigate(action) {
- switch (action && action.type) {
- case 'push':
- this.props.pushRoute(action.route)
- return true
- case 'back':
- case 'pop':
- return this._handleBackAction()
- default:
- return false
- }
- }
- _navigate(route){
- this.props._handleNavigate(route)
- }
- render(){
- const route = {
- type: 'push',
- route: {
- key: this.props.navKey,
- title: this.props.pageName,
- component: this.props.componentName
- }
- }
- return(
- <TouchableHighlight onPress={() => this._navigate(route)}>
- <Text style={styles}>{pr.pageName}</Text>
- </TouchableHighlight>
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement