<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:
options={{
title: 'My home',
...headerStyles(),
}}
So you need to import Dimensions
from react-native
and isTablet
from react-native-device-info
.
This implementation uses the default react navigation header if the device is not a tablet. 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.