导航栈未显示

huangapple go评论61阅读模式
英文:

navigation stack not displaying

问题

我有我的React Native代码,正在尝试为其添加导航,但它显示为空白。如果我尝试在堆栈中记录任何内容,控制台日志会显示,但屏幕本身不显示。这是我的屏幕:

import React, { useEffect, useState, useRef } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import "react-native-gesture-handler";

import BottomTabNavigator from "./BottomTabNavigator";
import ContinueScreen from "../screens/ContinueScreen";

const Stack = createNativeStackNavigator();

function MainStack() {
  console.log("jk");
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="ContinueScreen">
        <Stack.Screen name="ContinueScreen" component={ContinueScreen} />
        <Stack.Screen
          name="BottomTabNavigator"
          component={BottomTabNavigator}
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default MainStack;

我的package.json:

{
  "name": "app",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "1.17.11",
    "@react-navigation/bottom-tabs": "^6.5.2",
    "@react-navigation/native": "^6.1.1",
    "@react-navigation/native-stack": "^6.9.7",
    "expo": "~48.0.18",
    "expo-font": "^11.1.1",
    "expo-status-bar": "~1.4.4",
    "formik": "^2.4.1",
    "nativewind": "^2.0.11",
    "react": "18.2.0",
    "react-native": "0.71.8",
    "react-native-gesture-handler": "~2.8.0",
    "react-native-safe-area-context": "4.4.1",
    "react-native-screens": "~3.18.0",
    "tailwind-react-native-classnames": "^1.5.1",
    "yup": "^1.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@types/react": "~18.0.14",
    "@types/react-native": "^0.72.2",
    "tailwindcss": "^3.3.2",
    "typescript": "^4.9.4"
  },
  "private": true
}

如何让屏幕显示?如果我也将屏幕"ContinueScreen"添加到app.tsx中,它会正常显示,但如果我将其添加到MainStack中,则不会显示。

我的app.tsx:

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
// import tw from 'tailwind-react-native-classnames';
import OnboardingScreen from './app/screens/OnboardingScreen';
import ContinueScreen from './app/screens/ContinueScreen';
import BottomTabNavigator from './app/stacks/BottomTabNavigator';
import MainStack from './app/stacks/MainStack';

export default function App() {
  return (
    <View>
      {/* <OnboardingScreen /> */}
      <MainStack/>
    </View>
  );
}

const styles = StyleSheet.create({
  // container: {
  //   flex: 1,
  //   backgroundColor: '#fff',
  //   alignItems: 'center',
  //   justifyContent: 'center',
  // },
});

希望这能帮助你解决问题。如果还有其他问题,请随时提出。

英文:

i have my react native code, and im trying to add navigation to it, but its showing blank, if i try to console log anything in the stack the console log shows but the screens itself doesn't show, this is my screen:

import React, { useEffect, useState, useRef } from &quot;react&quot;;
import { NavigationContainer } from &quot;@react-navigation/native&quot;;
import { createNativeStackNavigator } from &quot;@react-navigation/native-stack&quot;;
import &quot;react-native-gesture-handler&quot;;

import BottomTabNavigator from &quot;./BottomTabNavigator&quot;;
import ContinueScreen from &quot;../screens/ContinueScreen&quot;;

const Stack = createNativeStackNavigator();

function MainStack() {
  console.log(&quot;jk&quot;);
  return (
    &lt;NavigationContainer&gt;
      &lt;Stack.Navigator initialRouteName=&quot;ContinueScreen&quot;&gt;
        &lt;Stack.Screen name=&quot;ContinueScreen&quot; component={ContinueScreen} /&gt;
        &lt;Stack.Screen
          name=&quot;BottomTabNavigator&quot;
          component={BottomTabNavigator}
        /&gt;
      &lt;/Stack.Navigator&gt;
    &lt;/NavigationContainer&gt;
  );
}

export default MainStack;

my package.json:

{
  &quot;name&quot;: &quot;app&quot;,
  &quot;version&quot;: &quot;1.0.0&quot;,
  &quot;main&quot;: &quot;node_modules/expo/AppEntry.js&quot;,
  &quot;scripts&quot;: {
    &quot;start&quot;: &quot;expo start&quot;,
    &quot;android&quot;: &quot;expo start --android&quot;,
    &quot;ios&quot;: &quot;expo start --ios&quot;,
    &quot;web&quot;: &quot;expo start --web&quot;
  },
  &quot;dependencies&quot;: {
    &quot;@react-native-async-storage/async-storage&quot;: &quot;1.17.11&quot;,
    &quot;@react-navigation/bottom-tabs&quot;: &quot;^6.5.2&quot;,
    &quot;@react-navigation/native&quot;: &quot;^6.1.1&quot;,
    &quot;@react-navigation/native-stack&quot;: &quot;^6.9.7&quot;,
    &quot;expo&quot;: &quot;~48.0.18&quot;,
    &quot;expo-font&quot;: &quot;^11.1.1&quot;,
    &quot;expo-status-bar&quot;: &quot;~1.4.4&quot;,
    &quot;formik&quot;: &quot;^2.4.1&quot;,
    &quot;nativewind&quot;: &quot;^2.0.11&quot;,
    &quot;react&quot;: &quot;18.2.0&quot;,
    &quot;react-native&quot;: &quot;0.71.8&quot;,
    &quot;react-native-gesture-handler&quot;: &quot;~2.8.0&quot;,
    &quot;react-native-safe-area-context&quot;: &quot;4.4.1&quot;,
    &quot;react-native-screens&quot;: &quot;~3.18.0&quot;,
    &quot;tailwind-react-native-classnames&quot;: &quot;^1.5.1&quot;,
    &quot;yup&quot;: &quot;^1.2.0&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@babel/core&quot;: &quot;^7.20.0&quot;,
    &quot;@types/react&quot;: &quot;~18.0.14&quot;,
    &quot;@types/react-native&quot;: &quot;^0.72.2&quot;,
    &quot;tailwindcss&quot;: &quot;^3.3.2&quot;,
    &quot;typescript&quot;: &quot;^4.9.4&quot;
  },
  &quot;private&quot;: true
}

how can I get the screen to show? if I also add the screen ContinueScreen in the app.tsx it shows without any issues, but if i add it in the MainSTack it doesn't show.

my app.tsx:

import { StatusBar } from &#39;expo-status-bar&#39;;
import { StyleSheet, Text, View } from &#39;react-native&#39;;
// import tw from &#39;tailwind-react-native-classnames&#39;;
import OnboradingScreen from &#39;./app/screens/OnboradingScreen&#39;;
import ContinueScreen from &#39;./app/screens/ContinueScreen&#39;;
import BottomTabNavigator from &#39;./app/stacks/BottomTabNavigator&#39;;
import MainStack from &#39;./app/stacks/MainStack&#39;;

export default function App() {
  return (
    &lt;View&gt;
     {/* &lt;OnboradingScreen /&gt; */}
     &lt;MainStack/&gt;
    &lt;/View&gt;
  );
}

const styles = StyleSheet.create({
  // container: {
  //   flex: 1,
  //   backgroundColor: &#39;#fff&#39;,
  //   alignItems: &#39;center&#39;,
  //   justifyContent: &#39;center&#39;,
  // },
});

答案1

得分: 1

似乎是一个样式问题。你能在View组件中添加flex: 1吗?

<View style={{ flex: 1 }}>
 <MainStack/>
</View>
英文:

It seems like a style issue. Can you add flex: 1 to View component?

&lt;View style={{ flex: 1 }}&gt;
 &lt;MainStack/&gt;
&lt;/View&gt;

huangapple
  • 本文由 发表于 2023年6月8日 06:45:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定