Skip to content

Instantly share code, notes, and snippets.

@dabit3
Created June 17, 2016 14:52
Show Gist options
  • Save dabit3/0d64b55bf203629342553b071155f4a0 to your computer and use it in GitHub Desktop.
Save dabit3/0d64b55bf203629342553b071155f4a0 to your computer and use it in GitHub Desktop.
React Native Navigator Experimental Part 2 — Implementing Redux navReducer.js
import { PUSH_ROUTE, POP_ROUTE } from '../constants/ActionTypes'
import { NavigationExperimental } from 'react-native'
const {
StateUtils: NavigationStateUtils
} = NavigationExperimental
const initialState = {
index: 0,
key: 'root',
routes: [{
key: 'home',
title: 'Home'
}]
}
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
}
}
export default navigationState
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment