我收到这个错误。我试图让用户按下选项卡,内容滚动到顶部,但我得到了跳转到索引不是一个功能
这是我的代码:
const NavigationBar = createBottomTabNavigator({
Home: {
screen: HomeNav, navigationOptions: ({ navigation }) => ({
title: 'Home',
tabBarOnPress: (scene, jumpToIndex) => {
console.log('onPress:', scene.route);
jumpToIndex(scene.index);
},
}),
}
})
根据您的活动版本的react导航,jumpToIndex
方法可能会折旧,您可以访问此处的文档https://reactnavigation.org/docs/bottom-tab-navigator/#tabpress了解如何在选项卡聚焦后滚动到顶部。
我猜您使用的是react原生导航v4,但您的代码已弃用
https://reactnavigation.org/docs/4.x/material-bottom-tab-navigator/#tabbaronpress
const NavigationBar = createBottomTabNavigator({
Home: {
screen: HomeNav, navigationOptions: ({ navigation }) => ({
title: 'Home',
tabBarOnPress: ({navigation, defaultHandler}) => {
// your logic
},
}),
}
})