如何在抽屉式导航屏幕中传递参数?

时间:2020-05-20 12:33:57

标签: react-native react-navigation react-navigation-drawer

import {ProfileScreen} from './ProfileScreen';
import {DashboardScreen} from './DashboardScreen';
 import {
 DrawerNavigator,
  createSwitchNavigator,
 createAppContainer,
 } from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {
createDrawerNavigator,
 DrawerNavigatorItems,
} from 'react-navigation-drawer';
import {NotificationScreen} from './NotificationScreen';


export class A_HomePage extends Component {
    static navigationOptions = {
header: null,
};
state = {
email: '',
 };

render() {

  this.setState({
    email: 'qwerty@gmail.com',
  });

return <AppContainer />;
  }
}
const ProfileStackNavigator = createStackNavigator(
  {
ProfileNavigator: ProfileScreen,
 },
{
defaultNavigationOptions: ({navigation}) => {
  return {
    headerLeft: (
      <Icon2
        style={{paddingLeft: 10}}
        onPress={() => navigation.openDrawer()}
        name="menu"
        size={30}
      />
    ),
  };
  },
 },
 );
 const NotificationScreenStackNavigator = createStackNavigator(
  {
 NotificationScreenNavigator: NotificationScreen,
 },
  {
 defaultNavigationOptions: ({navigation}) => {
  return {
    headerLeft: (
      <Icon2
        style={{paddingLeft: 10}}
        onPress={() => navigation.openDrawer()}
        name="menu"
        size={30}
      />
    ),
  };
  },
 },
);
const AppDrawerNavigator = createDrawerNavigator(
{ Profile: {
  screen: ProfileStackNavigator,
  navigationOptions: {
    drawerLabel: 'Profile',
    drawerIcon: ({tintColor}) => (
      <Icon name="glass" size={25} color="#00b33c" />
    ),
  },
},Notification: {
  screen:NotificationScreenStackNavigator ,
  navigationOptions: {
    drawerLabel: 'Notifications',
    drawerIcon: ({tintColor}) => (
      <Icon4 name="notification" size={25} color="#cc0099" />
    ),
  },
},
 },);

 const AppSwitchNavigator = createSwitchNavigator(
{ 
Profile: {screen: ProfileScreen}, 
Notification: {screen:NotificationScreen},
 },);
 const AppContainer = createAppContainer(AppSwitchNavigator); 

** 在这里,我创建了两个抽屉导航,主屏幕包含所有的堆栈 我如何将this.state.email传递到抽屉导航的配置文件和通知屏幕,或者如何访问屏幕配置文件和通知屏幕中的状态(这里是电子邮件),请帮助这可以改善我搜索过的项目工作它在google和docs中,但是没有任何想法**

1 个答案:

答案 0 :(得分:1)

将React Redux与Redux一起使用

Redux是中央状态管理系统,也可用于React-Native

React Redux Getting Started