切换选项卡时不会触发setOnNavigatorEvent回调

问题描述 投票:1回答:2

我正在开发一个由[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/6928824https://github.com/wix/react-native-navigation/issues/648),表明它应该有效,所以我不知道我错过了什么。 :/

任何帮助是极大的赞赏! :)

javascript react-native react-native-navigation wix-react-native-navigation
2个回答
0
投票

导致这种情况的原因之一是将qazxsw poi与qazxsw poi结合使用,如果你有一个实现setOnNavigatorEvent的屏幕包装器组件,那么你当前的监听器将无法工作。

addOnNavigatorEvent中所述

qazxsw poi不能与qazxsw poi一起使用

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

我建议尝试addOnNavigatorEvent而不是addOnNavigatorEvent


0
投票

这似乎是setOnNavigatorEvent中的一个错误(请注意插入符号):请参阅addOnNavigatorEvent

addOnNavigatorEvent已经开放但尚未合并。 :(

© www.soinside.com 2019 - 2024. All rights reserved.