用户在React Navigation中的最后一条路线上向右滑动后,如何导航回第一条路线?

时间:2019-03-26 14:46:44

标签: javascript react-native tabs react-navigation

我正在使用react-navigation中的createMaterialTopTabNavigator,并创建了一个自定义标签栏。我要实现的目标是,当用户位于最后一个选项卡上并向右滑动时,导航器会将其带回到第一个选项卡(基本上创建一个循环)。

这是我的导航器:

const myNavigator = 
    createMaterialTopTabNavigator(NavigatorConfig, {
    tabBarComponent: props => <CustomTabBar {...props} />,
});

CustomTabBar内,我正在渲染标签栏,如下所示:

<View> {this.props.navigationState.routes.map(this.renderItem)} </View>

然后renderItem渲染每个标签:

renderItem = (route, index) => {
  const { navigationState, jumpTo } = this.props;
  const focused = index === navigationState.index;
  const lastTab = index === navigationState.routes.length - 1;

  return (
  <TouchableWithoutFeedback
    key={route.key}
    onPress={() => jumpTo(route.routeName)}>

    ... tabcontent ...

  </TouchableWithoutFeedback>
  );
};

0 个答案:

没有答案