英文:
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 "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;
my 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
}
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 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
// import tw from 'tailwind-react-native-classnames';
import OnboradingScreen from './app/screens/OnboradingScreen';
import ContinueScreen from './app/screens/ContinueScreen';
import BottomTabNavigator from './app/stacks/BottomTabNavigator';
import MainStack from './app/stacks/MainStack';
export default function App() {
  return (
    <View>
     {/* <OnboradingScreen /> */}
     <MainStack/>
    </View>
  );
}
const styles = StyleSheet.create({
  // container: {
  //   flex: 1,
  //   backgroundColor: '#fff',
  //   alignItems: 'center',
  //   justifyContent: 'center',
  // },
});
答案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?
<View style={{ flex: 1 }}>
 <MainStack/>
</View>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论