问题
When the user hits a tab on a bottom nav bar while already on the screen I'd want to bring the user back to the top of the screen. Anyone know how I can do that using react-native-navigation?
回答1:
Figured it out.
Add this to the page you want to be scrolled up.
constructor(props) {
super(props);
this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
}
If you want more info on setting navigator events then you can check out:
https://wix.github.io/react-native-navigation/#/screen-api?id=listening-to-tab-selected-events
And then add this function:
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});
}
}
and add this to your ScrollView:
ref='_scrollView'
Thanks to this:
https://github.com/wix/react-native-navigation/issues/1719
来源:https://stackoverflow.com/questions/51144588/is-there-a-backtotop-in-react-native-navigation