我正在开发由SELECT DISTINCT product_id
FROM inventory
WHERE store_code = /* something */
ORDER BY product_id
和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 <Text>Whatever...</Text>
}
}
API方法),未调用我的toRootOnTabSelect
事件处理程序方法。
我在网上发现了多个帖子(即https://stackoverflow.com/a/51159091/6928824,https://github.com/wix/react-native-navigation/issues/648),这些帖子表明该帖子应该有效,所以我不知道自己缺少什么。 :/
任何帮助将不胜感激! :)
答案 0 :(得分:0)
可能导致使用setOnNavigatorEvent
与addOnNavigatorEvent
结合使用的原因之一,如果您具有实现addOnNavigatorEvent
的屏幕包装程序组件,则当前的侦听器将无法工作。
setOnNavigatorEvent
不能与addOnNavigatorEvent
结合使用
也
请记住,您不能同时使用
addOnNavigatorEvent
和setOnNavigatorEvent
。addOnNavigatorEvent
返回一个函数,该函数一旦调用将删除已注册的处理程序。
我建议尝试使用addOnNavigatorEvent
而不是setOnNavigatorEvent
答案 1 :(得分:0)
这似乎是react-native-navigation@^1.1.474
中的错误(请注意插入符号):请参见my issue on GitHub。
according pull request已打开,但尚未合并。 :(