我正在开发一个由 react-native@0.55.4 和 react-native-navigation@1.1.474 提供支持的应用程序 .
最初,只有一个登录屏幕(使用 Navigation.startSingleScreenApp ) . 当用户登录时,我调用 Navigation.startTabBasedApp (其中一个标签组件是我的 NavScreen ) . 每当用户更改为另一个选项卡时,应该显示选项卡堆栈的根,所以我尝试了这样的事情:
class NavScreen extends React.PureComponent {
constructor(props) {
super(props)
this.props.navigator.setOnNavigatorEvent(this.toRootOnTabSelect.bind(this))
}
toRootOnTabSelect(event) {
const {id} = event
if (["bottomTabSelected", "bottomTabReselected"].includes(id)) {
this.props.navigator.popToRoot({
animated: true,
animationType: "fade",
})
}
}
render() {
return Whatever...
}
}
但由于某些原因,我更改标签时没有调用 toRootOnTabSelect 事件处理程序方法(通过单击它们 - 而不是通过调用 switchToTab API方法) .
任何帮助是极大的赞赏! :)