【发布时间】:2019-02-07 16:35:56
【问题描述】:
我是 React Native 的新手。我想从侧面菜单导航到屏幕。我使用了 react-native-navigation Wix V2 库。如果有人能帮我举一个简单的例子,我将不胜感激。
【问题讨论】:
标签: click side-menu react-native-navigation-v2
我是 React Native 的新手。我想从侧面菜单导航到屏幕。我使用了 react-native-navigation Wix V2 库。如果有人能帮我举一个简单的例子,我将不胜感激。
【问题讨论】:
标签: click side-menu react-native-navigation-v2
首先你需要为sideMenu的中心栈设置ID。例如:
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({
root: {
sideMenu: {
right: {
component: {
name: 'SideMenu',
},
},
center: {
stack: {
id: 'STACK_ROOT_ID',
children: [
{
component: {
name: 'Login',
},
},
],
},
},
},
},
});
然后在您的侧边菜单中,您可以像这样在 onPress 菜单上推送您的注册屏幕。像这样:
Navigation.push('STACK_ROOT_ID', {
component: {
name: 'REGISTERED_SCREEN_NAME',
options: {
sideMenu: {
right: {
visible: false,
},
},
},
},
});
【讨论】:
有一个内置导航供 react native 使用,因为它提供了 react-native 导航(堆栈导航)。因为可以轻松地从侧面菜单进行导航
// 下面是创建侧边菜单的代码。
const RootDrawer = DrawerNavigator({
demo: { screen: demo },
demo2: { screen: demo2 },
}, {
contentComponent: NavigationDrawer
})
// 下面是侧面菜单视图和提供的用于从屏幕导航的链接。
<TouchableOpacity onPress = {() => this.props.navigation.navigate('demo')}>
<View style = {{height: responsiveHeight(8), justifyContent:'center'}}>
<Text style = {{fontSize: responsiveFontSize(2), color: 'black', fontFamily: 'Nunito-Regular', paddingLeft: 30 }} >My Cart</Text>
</View>
</TouchableOpacity>
{this.state.customer &&
<TouchableOpacity onPress = {() => this.props.navigation.navigate('demo1')}>
<View style = {{height: responsiveHeight(8), justifyContent:'center'}}>
<Text style = {{fontSize: responsiveFontSize(2), color: 'black', fontFamily: 'Nunito-Regular', paddingLeft: 30 }} >Account</Text>
</View>
</TouchableOpacity>}
【讨论】: