fix: use the JUMP_TO action for tab change

The index change event fires after swipe animation. If you quickly navigate to a new screen in stack before animation finishes, the index change event will fire after the previous navigation event. By this time, the tab navigator is not focused anymore. Using the JUMP_TO action instead of NAVIGATE avoids this issue.
This commit is contained in:
satyajit.happy
2019-04-23 20:36:44 +02:00
parent 4adb3a9223
commit 242625aa29

View File

@@ -6,7 +6,7 @@ import {
StackActions,
SceneView,
createNavigator,
NavigationActions,
SwitchActions,
} from '@react-navigation/core';
export type InjectedProps = {|
@@ -160,8 +160,17 @@ export default function createTabNavigator(TabView: React.ComponentType<*>) {
this.setState({ isSwiping: false });
};
_jumpTo = routeName =>
this.props.navigation.dispatch(NavigationActions.navigate({ routeName }));
_jumpTo = routeName => {
const { navigation } = this.props;
navigation.dispatch(
SwitchActions.jumpTo({
routeName,
key: navigation.state.key,
preserveFocus: true,
})
);
};
_isTabPress: boolean = false;