[英]React Navigation width is not 100% fit to screen on ios simulator
When I tried just to render the HomeScreen component not using Stack.Screen I was able to get 100% width but when I tried to use code bellow, 100% width screen is not working当我尝试不使用 Stack.Screen 渲染 HomeScreen 组件时,我能够获得 100% 的宽度,但是当我尝试使用下面的代码时,100% 宽度的屏幕不起作用
const HomeScreen = () => {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'red'}}>
<Text>Home Screen</Text>
</View>
);
}
const MainContainer = () => {
return (
<NavigationContainer >
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
/>
</Stack.Navigator>
</NavigationContainer>
);
Can you try with display: flex and remove flex:1你可以试试 display: flex 和 remove flex:1
Not only that, the width is zero if you set headerShown: false
.不仅如此,如果设置
headerShown: false
,宽度为零。
Just remove the outer View
of the NavigationContainer
.只需删除
NavigationContainer
的外部View
即可。 It works for me.这个对我有用。
Were you running the remote debugger when you were having this issue?当您遇到此问题时,您是否正在运行远程调试器? I had the same problem and it resolved when I turned it off.
我有同样的问题,当我关闭它时它解决了。
It seems like it might be a slow load issue and the stylesheets aren't being applied before rendering, so the screen is taking the width of the header text (I may be completely wrong about this though).看起来这可能是一个加载缓慢的问题,并且在渲染之前没有应用样式表,所以屏幕占用了 header 文本的宽度(尽管我可能完全错了)。 When I removed the style prop from my View component, saved it, then put it back and saved again it temporarily resolved the issue until I reloaded Expo.
当我从我的视图组件中删除样式道具,保存它,然后放回去并再次保存它暂时解决了这个问题,直到我重新加载 Expo。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.