切换标签页时不会触发setOnNavigatorEvent回调

时间:2018-07-07 18:04:46

标签: javascript react-native react-native-navigation wix-react-native-navigation

我正在开发由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/6928824https://github.com/wix/react-native-navigation/issues/648),这些帖子表明该帖子应该有效,所以我不知道自己缺少什么。 :/

任何帮助将不胜感激! :)

2 个答案:

答案 0 :(得分:0)

可能导致使用setOnNavigatorEventaddOnNavigatorEvent结合使用的原因之一,如果您具有实现addOnNavigatorEvent的屏幕包装程序组件,则当前的侦听器将无法工作。

documentation

中所述
  

setOnNavigatorEvent不能与addOnNavigatorEvent结合使用

  

请记住,您不能同时使用addOnNavigatorEventsetOnNavigatorEventaddOnNavigatorEvent返回一个函数,该函数一旦调用将删除已注册的处理程序。

我建议尝试使用addOnNavigatorEvent而不是setOnNavigatorEvent

答案 1 :(得分:0)

这似乎是react-native-navigation@^1.1.474中的错误(请注意插入符号):请参见my issue on GitHub

according pull request已打开,但尚未合并。 :(