当用户已经在屏幕上点击底部导航栏上的选项卡时,我希望将用户带回屏幕顶部。有人知道我如何使用react-native导航来做到这一点吗?
发布于 2018-07-04 00:16:10
我想通了。
将此内容添加到您希望向上滚动的页面。
constructor(props) {
super(props);
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
}如果你想了解更多关于设置导航器事件的信息,你可以查看:
https://wix.github.io/react-native-navigation/#/screen-api?id=listening-to-tab-selected-events
然后添加这个函数:
onNavigatorEvent(event) {
if (event.id === 'bottomTabSelected') {
console.log('Tab selected!');
}
if (event.id === 'bottomTabReselected') {
console.log('Tab reselected!');
this.refs._scrollView.scrollTo({x: 0, y: 0, animated: true});
}
}并将其添加到您的ScrollView中:
ref='_scrollView'多亏了这个:
https://stackoverflow.com/questions/51144588
复制相似问题