Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.subs = BackHandler.addEventListener('hardwareBackPress', () => {
if (!this._isMounted) {
this.subs && this.subs.remove();
} else {
// dispatch returns true if the action results in a state change,
// and false otherwise. This maps well to what BackHandler expects
// from a callback -- true if handled, false if not handled
return this.dispatch(NavigationActions.back());
}
});
}
}
return [StackActions.push({params, routeName})]
}
case RouteTreeGen.switchTab: {
return [NavigationActions.navigate({routeName: action.payload.tab})]
}
case RouteTreeGen.switchLoggedIn: {
return [NavigationActions.navigate({routeName: action.payload.loggedIn ? 'loggedIn' : 'loggedOut'})]
}
case RouteTreeGen.clearModals: {
const numModals = getNumModals(navigation)
return numModals ? [StackActions.pop({n: numModals})] : []
}
case RouteTreeGen.navigateUp:
return [NavigationActions.back({key: action.payload.fromKey})]
case RouteTreeGen.navUpToScreen: {
const fullPath = Constants._getFullRouteForNavigator(navigation.state)
const popActions: Array = []
const isInStack = fullPath.reverse().some(r => {
if (r.routeName === action.payload.routeName) {
return true
}
popActions.push(StackActions.pop({}))
return false
})
return isInStack ? popActions : []
}
case RouteTreeGen.resetStack: {
// TODO check for append dupes within these
const actions = action.payload.actions.reduce(
(arr, a) => [...arr, ...(oldActionToNewActions(a, navigation, true) || [])],
_removeScene = scene => {
const { navigation } = this.props;
navigation.dispatch(
NavigationActions.back({
key: scene.route.key,
immediate: true,
})
);
navigation.dispatch(StackActions.completeTransition());
};
const onCompleteAnimation = () => {
this.immediateIndex = null;
const backFromScene = scenes.find(s => s.index === toValue + 1);
if (backFromScene) {
navigation.dispatch(
NavigationActions.back({
key: backFromScene.route.key,
immediate: true,
})
);
navigation.dispatch(StackActions.completeTransition());
}
};