React Native Navigator / stack屏幕渲染无关

发布于 2025-02-09 14:43:49 字数 1768 浏览 2 评论 0原文

我遵循了反应本机导航的文档在这里,并让我的程序正常设置为没有错误的地方。我什至有一个< errorBoundary>包装器。但是,当没有错误并且一切正常工作时,我在屏幕上什么都没有,但是空格都没有。我有一个加载到堆栈导航器中的组件,但它不是渲染的。看看我的app.js文件...

export default function App() {
  
  const Stack = createNativeStackNavigator();

  const TestPage = () => {
    return(
      <View style={{flex: 1, backgroundColor: 'red'}}>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
      </View>
    )
  }

  return(
    <ErrorBoundary>
      <NavigationContainer>
        <KeyboardAvoidingView>
{/* ------------------------------------------------------------------------------ */}
          <View style={{flex: 1, backgroundColor: 'green'}}>
            <Stack.Navigator screenOptions={{headerShown: false}}>

              <Stack.Screen name="/" >
                {props => <TestPage />}
              </Stack.Screen>

            </Stack.Navigator>
          </View>
{/* ------------------------------------------------------------------------------ */}
        </KeyboardAvoidingView>
      </NavigationContainer>
    </ErrorBoundary>
  )
}

请注意,我不相信这是由于我没有明确创建主页,因为如果那是问题,我会像以前一样收到错误消息。它知道它应该呈现测试组件,但什么也不会出现。有什么想法吗?

I followed the documentation for React Native Navigation here, and have my program set up properly to the point where there are no errors. I even have an <ErrorBoundary> wrapper around that works. However, when there is no error and everything works as expected, I get nothing on my screen but whitespace. I have a component loaded into the Stack Navigator, but it is not rendering. Take a look at my App.js File...

export default function App() {
  
  const Stack = createNativeStackNavigator();

  const TestPage = () => {
    return(
      <View style={{flex: 1, backgroundColor: 'red'}}>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
        <Text style={{fontSize: 20, color: 'black'}}>SAMPLE TEXT</Text>
      </View>
    )
  }

  return(
    <ErrorBoundary>
      <NavigationContainer>
        <KeyboardAvoidingView>
{/* ------------------------------------------------------------------------------ */}
          <View style={{flex: 1, backgroundColor: 'green'}}>
            <Stack.Navigator screenOptions={{headerShown: false}}>

              <Stack.Screen name="/" >
                {props => <TestPage />}
              </Stack.Screen>

            </Stack.Navigator>
          </View>
{/* ------------------------------------------------------------------------------ */}
        </KeyboardAvoidingView>
      </NavigationContainer>
    </ErrorBoundary>
  )
}

Note that I don't believe this is due to the fact that I didn't explicitly create a HomePage, because if that was the issue I would receive an error message like I was before. It knows it should be rendering the test component, but nothing appears. Any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

披肩女神 2025-02-16 14:43:49

导航器或堆栈没有错,它是应用程序返回的主视图组件。
该代码看起来像这样...

return(
    <ErrorBoundary>
      <NavigationContainer>
        <KeyboardAvoidingView>
{/* ------------------------------------------------------------------------------ */}
          <View style={{flex: 1, backgroundColor: 'green'}}>
             // Other Stuff
          </View>
{/* ------------------------------------------------------------------------------ */}

当它看起来像这样...

return(
    <ErrorBoundary>
      <NavigationContainer>
        <KeyboardAvoidingView>
{/* ------------------------------------------------------------------------------ */}
          <View style={{height: '100%, width: '100%}}>
             // Other Stuff
          </View>
{/* ------------------------------------------------------------------------------ */}

这是因为基本view不能使其样式变得flex,因为它也没有相对,因此需要更明确地使屏幕的大小。

There was nothing wrong with the Navigator or the Stacks, it was the main View component inside of the App Component's return.
The code looked like this...

return(
    <ErrorBoundary>
      <NavigationContainer>
        <KeyboardAvoidingView>
{/* ------------------------------------------------------------------------------ */}
          <View style={{flex: 1, backgroundColor: 'green'}}>
             // Other Stuff
          </View>
{/* ------------------------------------------------------------------------------ */}

When it should look like this...

return(
    <ErrorBoundary>
      <NavigationContainer>
        <KeyboardAvoidingView>
{/* ------------------------------------------------------------------------------ */}
          <View style={{height: '100%, width: '100%}}>
             // Other Stuff
          </View>
{/* ------------------------------------------------------------------------------ */}

This is because the basemost View cannot have its style be flex, since it has nothing to be relative too, hence it needs to be made the size of the screen more explicitly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文