React native 如何使用tab navigator和screen navigator获取子屏幕的导航属性!,

React native 如何使用tab navigator和screen navigator获取子屏幕的导航属性!,,react-native,css-selectors,navigation,react-navigation,React Native,Css Selectors,Navigation,React Navigation,我不知道如何让导航属性切换到子屏幕 我认为我的代码是好的,但先天性的,它不工作。。。当我放置包含tab.navigator的导航容器时,tab navigator屏幕接受导航,但其他屏幕不接受导航,现在我更改了,我已将stack.navigator的屏幕包括在我的NavigationContainer中,但它也不起作用。。。我有一个错误: 无法注册导航器。你是否已将应用程序包装为 “导航容器” 我迷路了,有人能帮我吗? 非常感谢 import React from 'react'; import

我不知道如何让导航属性切换到子屏幕

我认为我的代码是好的,但先天性的,它不工作。。。当我放置包含tab.navigator的导航容器时,tab navigator屏幕接受导航,但其他屏幕不接受导航,现在我更改了,我已将stack.navigator的屏幕包括在我的NavigationContainer中,但它也不起作用。。。我有一个错误:

无法注册导航器。你是否已将应用程序包装为 “导航容器”

我迷路了,有人能帮我吗? 非常感谢

import React from 'react';
import { Image } from 'react-native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createStackNavigator} from "@react-navigation/stack";
import { NavigationContainer } from '@react-navigation/native';
import Authentication from '../../Screens/Authentication';
import Activities from '../../Screens/Activities';
import Login from '../../Screens/Authentication/Login';
import Register from '../../Screens/Authentication/Register';
import Tools from '../../Screens/Tools';
import Dashboard from '../../Screens/Dashboard';
import Orders from '../../Screens/Orders';
import Completed from '../../Screens/Orders/Completed';
import Current from '../../Screens/Orders/Current';
import Details from '../../Screens/Orders/Details';
import Settings from '../../Screens/Settings';
import Scan from '../../Screens/Tools/Scan';
import Products from '../../Screens/Tools/Products';
import Tickets from '../../Screens/Tools/Tickets';
import Welcome from '../../Screens/Welcome';
import i18n from '../../src/i18n';
import styles from '../../assets/styles';

const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();

export default function ScreenNavigator() {
  return(
    <NavigationContainer>
      <Stack.Navigator>       
        <Stack.Screen name = 'Orders' component = {Orders} options={{ title: i18n.t("orders.title") }}/> 
        <Stack.Screen name = 'Authentication' component = {Authentication} options={{ title: i18n.t("authentication.title") }}/>  
        <Stack.Screen name = 'Activities' component = {Activities} options={{ title: i18n.t("activities.title") }}/>  
        <Stack.Screen name = 'Login' component = {Login} options={{ title: i18n.t("login.title") }}/>
        <Stack.Screen name = 'Register' component = {Register} options={{ title: i18n.t("register.title") }}/>
        <Stack.Screen name = 'Tools' component = {Tools} options={{ title: i18n.t("tools.title") }}/>
        <Stack.Screen name = 'Scan' component = {Scan} options={{ title: i18n.t("scan.title") }}/>      
        <Stack.Screen name = 'Current' component = {Current} options={{ title: i18n.t("current.title") }}/>
        <Stack.Screen name = 'Completed' component = {Completed} options={{ title: i18n.t("completed.title") }}/>
        <Stack.Screen name = 'Details' component = {Details} options={{ title: i18n.t("details.title") }}/> 
        <Stack.Screen name = 'Products' component = {Products} options={{ title: i18n.t("products.title") }}/>      
        <Stack.Screen name = 'Tickets' component = {Tickets} options={{ title: i18n.t("tickets.title") }}/>
        <Stack.Screen name = 'Dashboard' component = {Dashboard} options={{ title: i18n.t("dashboard.title") }}/>
        <Stack.Screen name = 'Settings' component = {Settings} options={{ title: i18n.t("settings.title") }}/>
        <Stack.Screen name = 'Welcome' component = {Welcome} options={{ title: i18n.t("welcome.title") }}/>
      </Stack.Navigator>
    </NavigationContainer>
  )
}

 export function AppNavigation() {
  return (    
      <Tab.Navigator tabBarOptions={{activeTintColor: 'black',
                     labelStyle: {fontSize: 12, color: 'white'}, 
                     style: {backgroundColor: '#F78400'},
                     }}>
        <Tab.Screen
          name={i18n.t("orders.title")}
          component={ScreenNavigator}
          options={{
              tabBarIcon: ({ focused, horizontal, tintColor }) => {
                return (
                  <Image
                    source={require("../../assets/images/orders.png")}
                    style={styles.icon}
                  />
                );
              }
          }}
        />
        <Tab.Screen
          name={i18n.t("dashboard.title")}
          component={Dashboard}
          options={{
            tabBarIcon: ({ focused, horizontal, tintColor }) => {
              return (
                <Image
                  source={require("../../assets/images/dashboard.png")}
                  style={styles.icon}
                />
              );
            }
          }}
        />
        <Tab.Screen
          name={i18n.t("tools.title")}
          component={Tools}
          options={{
            tabBarIcon: ({ focused, horizontal, tintColor }) => {
              return (
                <Image
                  source={require("../../assets/images/tools.png")}
                  style={styles.icon}
                />
              );
            }
          }}
        />
        <Tab.Screen
          name={i18n.t("settings.title")}
          component={Settings}
          options={{
            tabBarIcon: ({ focused, horizontal, tintColor }) => {
              return (
                <Image
                  source={require("../../assets/images/settings.png")}
                  style={styles.icon}
                />
              );
            }
          }}
        />
      </Tab.Navigator>    
  )
}
从“React”导入React;
从“react native”导入{Image};
从“@react navigation/bottom tabs”导入{createBottomTabNavigator};
从“@react navigation/stack”导入{createStackNavigator};
从'@react-navigation/native'导入{NavigationContainer};
从“../../Screens/Authentication”导入身份验证;
从“../../Screens/Activities”导入活动;
从“../../Screens/Authentication/Login”导入登录名;
从“../../Screens/Authentication/Register”导入寄存器;
从“../../Screens/Tools”导入工具;
从“../../Screens/Dashboard”导入仪表板;
从“../../Screens/Orders”导入订单;
从“../../Screens/Orders/Completed”导入已完成;
从“../../Screens/Orders/Current”导入当前数据;
从“../../Screens/Orders/Details”导入详细信息;
从“../../Screens/Settings”导入设置;
从“../../Screens/Tools/Scan”导入扫描;
从“../../Screens/Tools/Products”导入产品;
从“../../Screens/Tools/Tickets”导入票据;
从“../../Screens/Welcome”导入欢迎;
从“../../src/i18n”导入i18n;
从“../../assets/styles”导入样式;
const Tab=createBottomTabNavigator();
const Stack=createStackNavigator();
导出默认函数ScreenNavigator(){
返回(
)
}
导出函数AppNavigation(){
报税表(
{
返回(
);
}
}}
/>
{
返回(
);
}
}}
/>
{
返回(
);
}
}}
/>
{
返回(
);
}
}}
/>
)
}
App.js:

import React from "react";
import {
  View,
  Text,
  StatusBar,
  Image,
  ActivityIndicator,
} from "react-native";
import {
  retrieveAppLang,
  userSessionActive
} from "./src/common/Preferences";
import i18n from "./src/i18n";
import styles from './assets/styles';
import Authentication from './Screens/Authentication'
import { ScreenNavigator, AppNavigation } from './src/Navigation';


export default class App extends React.Component {
  constructor(props) {
    super(props);
      this.state = {
        isFirstConnection: true,
        status: 0,      
      };
  }

  async UNSAFE_componentWillMount() {
    let lang = await retrieveAppLang();
    let isConnected = await userSessionActive();

    if (lang.length == 2) {
      i18n.changeLanguage(lang);
    }

    if (isConnected === true && this.props && this.props.navigation) {
      this.props.navigation.navigate("ScreenNavigator");
    }
  }

  async componentDidMount() {
 
    const data = await this.performTimeConsumingTask();
    if (data !== null) {
      this.setState({
        isFirstConnection: false,
        status: 1,
      });
    }
  }

    async performTimeConsumingTask() {
      return new Promise((resolve) =>
        setTimeout(() => {
          resolve("result");
        }, 750)
      );
    };

  render() {
    if (this.state.status == 1) {
      if (this.state.isFirstConnection ) {
        return <Authentication />;
      } else {
        return <AppNavigation />
      }
    }

    return (
        <View style={styles.container}>
          <StatusBar hidden={true} />
          <View style={styles.subContainer}>
            <Image
              style={styles.logo}
              source={require("./assets/images/logo.png")}
            />
            <ActivityIndicator size="large" color="#F78400" />
            <Text>{i18n.t("app.loading") + "..."}</Text>
          </View>
        </View>
    );
  }
}
从“React”导入React;
进口{
看法
文本,
状态栏,
形象,,
活动指示器,
}从“反应本族语”;
进口{
检索Applang,
用户会话活动
}来自“/src/common/Preferences”;
从“/src/i18n”导入i18n;
从“./assets/styles”导入样式;
从“/Screens/Authentication”导入身份验证
从“/src/Navigation”导入{ScreenNavigator,AppNavigation};
导出默认类App扩展React.Component{
建造师(道具){
超级(道具);
此.state={
是的,
状态:0,
};
}
异步不安全组件willmount(){
let lang=等待检索applang();
let isConnected=wait userSessionActive();
if(lang.length==2){
i18n.改变语言(lang);
}
if(isConnected==true&&this.props&&this.props.navigation){
this.props.navigation.navigate(“屏幕导航器”);
}
}
异步组件didmount(){
const data=等待此操作。performTimeConsumingTask();
如果(数据!==null){
这是我的国家({
isFirstConnection:false,
现状:1,
});
}
}
异步performTimeConsumingTask(){
返回新承诺((解决)=>
设置超时(()=>{
决议(“结果”);
}, 750)
);
};
render(){
if(this.state.status==1){
if(this.state.isFirstConnection){
返回;
}否则{
返回
}
}
返回(
{i18n.t(“应用程序加载”)+“…”}
);
}
}

NavigationContainer应该在根级别,在您的情况下,tab navigator是根,您应该用NavigationContainer将其包装好,然后我更改我的帖子。但是当我这样做时,例如身份验证之类的屏幕不会获得导航属性。您在两个位置使用身份验证,堆栈中的导航器将获得导航属性。因此,在app.js中,我不应该单独调用身份验证。我应该尝试“”?很抱歉,我错过了您的答案,我从一开始就使用了:我从app.js设置它。非常感谢你的帮助