我是反应原生的新手,我正在尝试使用路由器和侧边菜单构建应用程序,其中包含指向此菜单中其他页面的链接。
好吧,我实际上正在使用gb-native-router和react-native-side-menu来执行此操作。实际上我找到了2个解决方案。
第一个解决方案:
<SideMenu menu={menu}> //here, the sidemenu is outside the router, i can't put in inner (the chat will slide but not the Navigator)
<Router
firstRoute={Routes.Main.App}
headerStyle={Styles.NavBar.container}
titleStyle={Styles.NavBar.navContent}
borderBottomWidth={Styles.Props.NavBar.borderBottomWidth}
borderColor={Styles.Props.NavBar.borderColor}
/>
</SideMenu>
第二个解决方案:
在test.js文件中包含侧边菜单(请参阅链接)以执行以下操作:
<SideMenu menu={menu}>
<View><Chat /></View>
</SideMenu>
问题:第一个解决方案运行良好,但是当我尝试做#34; this.props.toRoute({})&#34;时,此功能未定义(因为我觉得菜单不在路由器中) 第二种解决方案是,当我访问侧边菜单时,路由器(导航器)不会随页面的其余部分移动(因为他不在侧边菜单中:p)。
此探针的任何帮助?我想我可以使用NSNotificationCenter向所有应用程序发送信号,并在路由器内添加一个侦听器以尝试正确路由......但我想找到一种更简单,更好的方法。
您可以在此处查看更多代码:https://rnplay.org/apps/Xr8PPA
感谢您的帮助!
编辑:
这里是来自react-native-side-menu的一个简短的index.js代码:
render() {
let menu = null;
/**
* If menu is ready to be rendered
*/
if (this.state.shouldRenderMenu) {
menu = <View style={styles.menu}>{this.props.menu}</View>;
}
return (
<View style={styles.container} onLayout={this.onLayoutChange.bind(this)}>
{menu}
{this.getContentView()}
</View>
);
}
似乎我的menu.js菜单只在视图中呈现。所以我不知道如何从这里访问路由器...... :(
答案 0 :(得分:0)
尝试使用this.refs
并同时调用toRoute
函数,而不是从父级调用,而是从父级调用。
由于依赖关系,rnplay上的代码被破坏了,但我更新了代码: