Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 使用堆栈导航器时如何传递屏幕道具_React Native_Expo - Fatal编程技术网

React native 使用堆栈导航器时如何传递屏幕道具

React native 使用堆栈导航器时如何传递屏幕道具,react-native,expo,React Native,Expo,我正在尝试将所有3个窗口的参数传递到我的选项卡中。我只是不知道我们应该在这里放置ScreenProps,以及这是否是向3个类发送参数的正确方法。是否也需要在此类中传递参数,或者在登录后导航到选项卡时传递参数this.props.navigation.navigate('Main',{name:'1})只需立即传递名称1即可在所有选项卡中获取它 import React from 'react'; import { Platform} from 'react-native'; import { c

我正在尝试将所有3个窗口的参数传递到我的选项卡中。我只是不知道我们应该在这里放置
ScreenProps
,以及这是否是向3个类发送参数的正确方法。是否也需要在此类中传递参数,或者在登录后导航到选项卡时传递参数
this.props.navigation.navigate('Main',{name:'1})
只需立即传递名称1即可在所有选项卡中获取它

import React from 'react';
import { Platform} from 'react-native';
import { createStackNavigator, createBottomTabNavigator } from 'react-navigation';

import TabBarIcon from '../components/TabBarIcon';
import HomeScreen from '../screens/HomeScreen';
import LinksScreen from '../screens/LinksScreen';
import Profile from '../screens/ProfileToUse';


const HomeStack = createStackNavigator({
 Home: HomeScreen,
});

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon
     focused={focused}
     name={
       Platform.OS === 'ios'
        ? `ios-information-circle${focused ? '' : '-outline'}`
        : 'md-information-circle'
    }
  /> 
 )
};

const LinksStack = createStackNavigator({
  Links: LinksScreen,
 });

LinksStack.navigationOptions = {
  tabBarLabel: 'Contacts',
  tabBarIcon: ({ focused }) => (
     <TabBarIcon
      focused={focused}
       name={Platform.OS === 'ios' ? `ios-link${focused ? '' : '-outline'}` : 'md-link'}
     />
   ),
 };

  const ProfileStack = createStackNavigator({
    Profile: Profile,
  });

 ProfileStack.navigationOptions = {
  tabBarLabel: 'Profile',
  tabBarIcon: ({ focused }) => (
     <TabBarIcon
     focused={focused}
     name={Platform.OS === 'ios' ? `ios-options${focused ? '' : '-outline'}` : 'md-profile'}
     />
   ),
 };


export default createBottomTabNavigator({
HomeStack,
LinksStack,
ProfileStack,
},
{
  tabBarOptions: {
    showLabel: true,
    activeTintColor: '#F8F8F8',
    inactiveTintColor: '#586589',
    style: {
     backgroundColor: '#273746'
   },
    tabStyle: {}
  }
},


);
从“React”导入React;
从“react native”导入{Platform};
从“反应导航”导入{createStackNavigator,CreateBoottomTabNavigator};
从“../components/TabBarIcon”导入TabBarIcon;
从“../screens/HomeScreen”导入主屏幕;
从“../screens/LinksScreen”导入LinksScreen;
从“../screens/ProfileToUse”导入配置文件;
const HomeStack=createStackNavigator({
主页:主屏幕,
});
HomeStack.navigationOptions={
tabBarLabel:“主页”,
tabBarIcon:({focused})=>(
)
};
const LinksStack=createStackNavigator({
链接:LinksScreen,
});
LinksStack.navigationOptions={
tabBarLabel:“联系人”,
tabBarIcon:({focused})=>(
),
};
const ProfileStack=createStackNavigator({
简介:简介,,
});
ProfileStack.navigationOptions={
tabBarLabel:“配置文件”,
tabBarIcon:({focused})=>(
),
};
导出默认CreateBoottomTabNavigator({
本垒打,
林克斯塔克,
ProfileStack,
},
{
选项卡选项:{
showLabel:true,
activeTintColor:“#F8”,
颜色:“#586589”,
风格:{
背景颜色:“#273746”
},
tabStyle:{}
}
},
);

一次只能将screenprops传递给一个屏幕,在第一个屏幕中调用
this.props.navigation.navigate('Main',{name:'1})
,然后调用
var p=this.props.navigation.getParam('name'| |'No name')


您可能希望使用一些库来避免这种情况,例如Redux,甚至reactn。

当我将它传递给main时,它会转到上面的类。我如何才能在my class
道具中实际看到它。导航
不会获得您没有发布的类的值。。。导航到一个屏幕,然后将其粘贴到导航到
componendddimount(){var p=this.props.navigation.getParam('name'| |'No name');alert(p)}
的页面中,您可以在这里发布之前检查基本文档