本文介绍了React NavigatorIOS 没有在 replace() 上更新标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的根组件中使用 NavigatorIOS 组件,并且想要在登录和注册屏幕之间切换:

I'm using a NavigatorIOS component in my root component, and want to toggle between a login an register screen:

navToLogin() {
    this.refs.nav.replace({
        title: "Login",
        component: LoginScene,
        rightButtonTitle: "Sign Up",
        onRightButtonPress: this.navToRegister.bind(this)
    });
}

navToRegister() {
    this.refs.nav.replace({
        title: "Sign Up",
        component: RegisterScene,
        rightButtonTitle: "Login",
        onRightButtonPress: this.navToLogin.bind(this)
    });
}

render() {
    return (
        <NavigatorIOS
            ref = "nav"
            style={styles.navigator}
            initialRoute={{
                component: LoginScene,
                title: "Login",
                rightButtonTitle: "Sign Up",
                onRightButtonPress: this.navToRegister.bind(this)
            }}
        />
    );
}

尽管视图已正确更新,但在 nav.replace() 调用后标题和 rightButton 不会更改.当我使用 nav.push() 时,一切都按预期工作.

Although the view is updated properly, the title and rightButton do not change after the nav.replace() invocation. When I'm using nav.push() everything works as expected.

我是否以某种方式错误地使用了这个组件?

Am I using this component wrong somehow?

推荐答案

你没有用错,这是 NavigatorIOS 的一个 bug.如果可以的话,可能值得使用 Navigator,因为它得到更好的支持(Facebook 实际上在内部使用它)

You're not using it wrong, this is a bug NavigatorIOS. If you can it's probably worth using Navigator instead as that's better supported (Facebook are actually using it themselves internally)

这篇关于React NavigatorIOS 没有在 replace() 上更新标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:54