我正在开发一个由[email protected]
和[email protected]
提供支持的应用程序。
最初,只有一个登录屏幕(使用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 <Text>Whatever...</Text>
}
}
但由于某些原因,我更改标签时没有调用我的toRootOnTabSelect
事件处理程序方法(通过单击它们 - 而不是通过调用switchToTab
API方法)。
我在网上发现了多个帖子(即https://stackoverflow.com/a/51159091/6928824,https://github.com/wix/react-native-navigation/issues/648),表明它应该有效,所以我不知道我错过了什么。 :/
任何帮助是极大的赞赏! :)
导致这种情况的原因之一是将qazxsw poi与qazxsw poi结合使用,如果你有一个实现setOnNavigatorEvent
的屏幕包装器组件,那么你当前的监听器将无法工作。
如addOnNavigatorEvent
中所述
qazxsw poi不能与qazxsw poi一起使用
也
请记住,你不能同时使用
addOnNavigatorEvent
和documentation。setOnNavigatorEvent
返回一个函数,一旦调用将删除已注册的处理程序。
我建议尝试addOnNavigatorEvent
而不是addOnNavigatorEvent
这似乎是setOnNavigatorEvent
中的一个错误(请注意插入符号):请参阅addOnNavigatorEvent
。
addOnNavigatorEvent
已经开放但尚未合并。 :(