[英]How to move react navigation Stack header to bottom of the screen in React native?
<Stack.Screen name="addBusiness" component={BusinessScreen} options={{ title: 'My home', header: (navigationOptions) => ( <View style={{ position: 'relative', bottom: 0, height: 80, width: '100%', backgroundColor: '#dbdbdb', }} > <Text>HOME</Text> </View> ), }} />
You can do something like this:你可以这样做:
import {isTablet} from 'react-native-device-info';
// ...
const headerStyles = () => {
if (isTablet()) {
return {
header: () => (
<View
style={{
position: 'absolute',
top: Dimensions.get('window').height - 60,
left: 0,
right: 0,
height: 60,
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<Text>HOME</Text>
</View>
),
};
}
}
headerStyles
can then be used like this: headerStyles
然后可以像这样使用:
options={{
title: 'My home',
...headerStyles(),
}}
So you need to import Dimensions
from react-native
and isTablet
from react-native-device-info
.所以你需要从react-native
和isTablet
从react-native-device-info
导入Dimensions
。
This implementation uses the default react navigation header if the device is not a tablet.如果设备不是平板电脑,此实现使用默认的反应导航 header。 So if you also want to have a custom header on mobile you similarly need to return a header component in an else statement or after the if statement.因此,如果您还想在移动设备上使用自定义 header,您同样需要在 else 语句中或 if 语句之后返回 header 组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.