React Native Navigator / stack屏幕渲染无关
我遵循了反应本机导航的文档在这里,并让我的程序正常设置为没有错误的地方。我什至有一个< 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导航器或堆栈没有错,它是应用程序返回的主视图组件。
该代码看起来像这样...
当它看起来像这样...
这是因为基本
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...
When it should look like this...
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.