react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

How to block app exit when i press android hardware back button on top level of navigation

Open zhenliliu opened this issue 9 years ago • 4 comments

TabNavigationIndex.router.getStateForAction = (action, state) => {

if(state && state.index == 0 && action.type == 'Navigation/BACK'){
   
}
return defaultGetStateForAction(action, state);

};

in this function how to block app exit

zhenliliu avatar May 13 '17 10:05 zhenliliu

Generally returning true while prevent the app exit.

Moumene avatar May 13 '17 12:05 Moumene

but when i return true it remind me such as this 'Cannot read property 'forEach' of undefine'

zhenliliu avatar May 14 '17 02:05 zhenliliu

return state;

nihgwu avatar May 14 '17 03:05 nihgwu

yes i have solved this problem by ' return { ...state, index: state.routes.length - 1, };'

zhenliliu avatar May 14 '17 03:05 zhenliliu