gpt4 book ai didi

react-native - React - 原生抽屉导航导航嵌套导航

转载 作者:行者123 更新时间:2023-12-04 05:11:45 25 4
gpt4 key购买 nike

目前在我正在构建的 react-native 应用程序中,我有一个包含两个屏幕的 Drawer Navigator。
对于导航,我使用的是 react-navigation。
https://reactnavigation.org/docs/intro/

代码如下,

import { DrawerNavigator } from 'react-navigation'
export default drawernav = DrawerNavigator(
{
Login: {Screen: Login},
Main : {Screen: Main }
}
)

虽然登录在抽屉导航器中,但我想要它,以便登录屏幕没有抽屉导航功能,但主屏幕将登录和主要作为抽屉导航器中的两个选项。
但是,现在登录屏幕也有抽屉导航器。有没有办法让登录抽屉导航功能消失?

最佳答案

请参阅以下帖子,这非常有帮助。
https://github.com/react-navigation/react-navigation/issues/131 .
建议了多种方法。
kyaroru 提供了一个完整的工作示例,如下所示:
https://github.com/kyaroru/ReactNavDrawer .

下面是一个更简单的例子:

应用程序.js

import React from 'react';
import { createStackNavigator , createDrawerNavigator } from 'react-navigation';
import LoginScreen from './LoginScreen';
import SignupScreen from './SignupScreen';
import HomeScreen from './HomeScreen';
import DrawerButton from './DrawerButton';
import SettingScreen from './SettingScreen';

const StackNavigator = createStackNavigator ({

Login: {
screen: LoginScreen,
},

Signup: {
screen: SignupScreen,
},

Home: {
screen: HomeScreen,
},

Sitting: {
screen: SettingScreen,
},

},
{
navigationOptions: ({navigation}) => ({
headerLeft: <DrawerButton navigation={navigation} />,
}),
}
);

const DrawerNavigator = createDrawerNavigator({
Menu: {
screen: StackNavigator,
},

Signup: {
screen: SignupScreen,
},

Sitting: {
screen: SettingScreen,
},

});

export default DrawerNavigator;

抽屉按钮.js
import React from 'react';
import { TouchableOpacity, Platform } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import PropTypes from 'prop-types';


const DrawerButton = ({ navigation }) => (
<TouchableOpacity
onPress={() => navigation.openDrawer()}
>
<Ionicons name={Platform.OS === 'ios' ? 'ios-menu' : 'md-menu'} size={28} />
</TouchableOpacity>
);


DrawerButton.propTypes = {
navigation: PropTypes.object.isRequired,
};

export default DrawerButton;

关于react-native - React - 原生抽屉导航导航嵌套导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com