我正在使用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>
);
};