如何在Stack.Screen
包含标头的内容中垂直居中计算内容?
当前,如果我尝试使元素在屏幕上垂直居中,由于Stack.Screen
标题,它将稍微移至屏幕底部。我想这个尺寸考虑到计算不使用margin-top: -N
其中N
为标头的大小。
为什么没有保证金?因为它增加了处理iOS和Android设备的复杂性。
navigator.component.tsx
<Stack.Navigator>
<Stack.Screen
name='SignIn'
component={SignInComponent}
/>
</Stack.Navigator>
登录组件.tsx
const SignInComponent = () => {
return (
<View style={{ height: '100%', justifyContent: 'center' }}>
<Text>Example</Text>
</View>
)
}
为什么没有保证金?因为它增加了处理iOS和Android设备的复杂性。
它增加了什么复杂性?
import { useHeaderHeight } from '@react-navigation/stack';
// ...
const headerHeight = useHeaderHeight();
<View style={{ height: '100%', justifyContent: 'center', marginTop: -headerHeight }}>
<Text>Example</Text>
</View>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句