Skip to content

Instantly share code, notes, and snippets.

@drmas
Forked from dabit3/navReducer.js
Last active June 21, 2016 09:58
Show Gist options
  • Save drmas/76f68137da7068bf0e0d6a48482e8def to your computer and use it in GitHub Desktop.
Save drmas/76f68137da7068bf0e0d6a48482e8def 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 StateUtils.push(state, action.route)
case POP_ROUTE:
if (state.index === 0 || state.routes.length === 1) return state
return StateUtils.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