【问题标题】:How to switch to another module in react native?react-native 如何切换到另一个模块?
【发布时间】:2015-07-13 10:45:50
【问题描述】:

刚刚实现了一个登录页面。

用户点击登录按钮后。 如何导航到我的主页模块?

代码应如下所示:

登录模块:

class MyClient extends Component{
    render() {
        return (
            <View style={styles.container}>
                <TouchableHighlight style={styles.button}
                    onPress={this.login.bind(this)}>
                </TouchableHighlight>
            </View>
        );
    }
    login() {
        //How to switch to home view here?
    }
}

module.exports = MyClient;

主页模块:

class Home extends Component{
    render() {
        return (
            <View>
                 <Text>This is home page</Text>
            </View>
        );
    }
}
module.experts = Home;

我不想使用导航器这个组件因为'我认为主模块和登录模块不应该是父子关系。

有没有办法在这两个页面之间切换?

【问题讨论】:

  • 您必须使用导航器。您可以尝试使用“替换”而不是“推送”。有了这个,您可以实现组件之间的即时导航。 this.props.navigator.replace({ title: 'Home', component: Home, });
  • @nicopasso 尝试将 NavigatorIOS 添加到我的应用程序中,有没有办法隐藏导航栏?
  • @nicopasso navigationBarHidden 正在为我工​​作。谢谢你的帮助。 :)
  • 是的。 NavigatorIOS 组件有“navigationBarHidden”属性。 &lt;NavigatorIOS navigationBarHidden = 'true' /&gt;
  • @nicopasso 太酷了:)

标签: reactjs react-native


【解决方案1】:

您必须使用导航器。您可以尝试使用“replace”而不是“push”。有了它,您可以实现组件之间的即时导航。

this.props.navigator.replace({ 
    title: 'Home', component: Home 
});

如果您想隐藏导航栏,可以使用 NavigatorIOS 组件的“navigationBarHidden”属性。

  <NavigatorIOS navigationBarHidden = 'true' />

【讨论】:

  • 我想知道如何在子视图中再次显示导航器?
  • @Asaka 我想你可以试试this module
猜你喜欢
  • 2022-07-23
  • 2021-10-27
  • 1970-01-01
  • 2017-05-03
  • 2011-04-13
  • 1970-01-01
  • 1970-01-01
  • 2021-07-05
  • 1970-01-01
相关资源
最近更新 更多