Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerdan committed Feb 6, 2017
1 parent 1312133 commit 637820f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/tabBar/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const reducer = (state=defaultState,action) => {
}
break;

case 'Navigation/BACK':
if ( action.key.routeIndexZero ) {
case 'ANDROID_BACK_ACTION':
if ( action.payload.routeIndexZero ) {
let currentIndex = state.index
return { ...state, index: currentIndex - 1 }
} else {
Expand Down
6 changes: 3 additions & 3 deletions app/tabBar/views/TabBarNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class TabBarNavigation extends React.Component {
handleBackAction = () => {
const { navigationState: {index: tabIndex}, tabOneIndex, tabTwoIndex, tabThreeIndex } = this.props

console.log('back action..', this.props)


const tabIndexArray = [ tabOneIndex, tabTwoIndex, tabThreeIndex ]
const routeIndexZero = (tabIndexArray[tabIndex] === 0) ? true:false

if ( tabIndex === 0 && routeIndexZero ) {
return false
} else {
this.navigator.props.navigation.goBack({tabIndex:tabIndex,routeIndexZero:routeIndexZero})
this.navigator.props.navigation.dispatch(
{type:'ANDROID_BACK_ACTION',payload:{routeIndexZero:routeIndexZero,tabIndex:tabIndex}}
)
return true
}
}
Expand Down
15 changes: 13 additions & 2 deletions app/tabOne/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const defaultState = {
const reducer = (state=defaultState,action) => {
switch (action.type) {
case 'Navigation/NAVIGATE':
let index = findRouteIndexByName(routeStack,action.routeName)
var index = findRouteIndexByName(routeStack,action.routeName)
if ( index !== -1 ) {
let newStack = state.routes.concat([routeStack[index]])
return { ...state, index: newStack.length - 1, routes:newStack }
Expand All @@ -20,7 +20,18 @@ const reducer = (state=defaultState,action) => {
break;

case 'Navigation/BACK':
let { tabIndex, routeIndexZero } = action.key
var index = findRouteIndexByName(routeStack,action.key)
if ( index !== -1 ) {
let newStack = state.routes.slice(0,state.index)
let newIndex = state.index - 1
return { ...state, index:newIndex, routes:newStack }
} else {
return state
}
break;

case 'ANDROID_BACK_ACTION':
let { tabIndex, routeIndexZero } = action.payload
// check if the back action is for this tab and if the currentIndex is at zero
if (tabIndex === 0 && !routeIndexZero) {
let newStack = state.routes.slice(0,state.index)
Expand Down
16 changes: 14 additions & 2 deletions app/tabThree/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ const reducer = (state=defaultState,action) => {
break;

case 'Navigation/BACK':
let { tabIndex, routeIndexZero } = action.key
var index = findRouteIndexByName(routeStack,action.key)
if ( index !== -1 ) {
let newStack = state.routes.slice(0,state.index)
let newIndex = state.index - 1
return { ...state, index:newIndex, routes:newStack }
} else {
return state
}
break;


case 'ANDROID_BACK_ACTION':
let { tabIndex, routeIndexZero } = action.payload
// check if the back action is for this tab and if the currentIndex is at zero
if (tabIndex === 2 && !routeIndexZero) {
if (tabIndex === 2 && !routeIndexZero ) {
let newStack = state.routes.slice(0,state.index)
let newIndex = state.index - 1
return { ...state, index:newIndex, routes:newStack }
Expand Down
2 changes: 1 addition & 1 deletion app/tabThree/views/TabThreeScreenThree.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class TabThreeScreenThree extends React.Component {
}}>
<Text>{ 'Tab Three Screen Three' }</Text>
<TouchableOpacity
onPress={ () => this.props.navigation.goBack({tabIndex:2,routeIndexZero:false}) }
onPress={ () => this.props.navigation.goBack('TabThreeScreenThree') }
style={{
padding:20,
borderRadius:20,
Expand Down
4 changes: 2 additions & 2 deletions app/tabThree/views/TabThreeScreenTwo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export default class TabThreeScreenTwo extends React.Component {
}}>
<Text>{'Go to screen three'}</Text>
</TouchableOpacity>

<TouchableOpacity
onPress={ () => this.props.navigation.goBack({tabIndex:2,routeIndexZero:false}) }
onPress={ () => this.props.navigation.goBack('TabThreeScreenTwo') }
style={{
padding:20,
borderRadius:20,
Expand Down
14 changes: 13 additions & 1 deletion app/tabTwo/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ const reducer = (state=defaultState,action) => {
break;

case 'Navigation/BACK':
let { tabIndex, routeIndexZero } = action.key
var index = findRouteIndexByName(routeStack,action.key)
if ( index !== -1 ) {
let newStack = state.routes.slice(0,state.index)
let newIndex = state.index - 1
return { ...state, index:newIndex, routes:newStack }
} else {
return state
}
break;


case 'ANDROID_BACK_ACTION':
let { tabIndex, routeIndexZero } = action.payload
// check if the back action is for this tab and if the currentIndex is at zero
if (tabIndex === 1 && !routeIndexZero) {
let newStack = state.routes.slice(0,state.index)
Expand Down

0 comments on commit 637820f

Please sign in to comment.