Setting `headerLeft` on Android modal hides title
See original GitHub issueGreetings! Either I’ve found a bug (and have failed to find a solution online), or my complete lack of understanding which, if the latter, I will retire into the hills of Saskatchewan, should I ever find one.
When presenting a screen modally inside a native Stack Navigator - on android - via presentationStyle: modal
, everything works as one would expect. However, when I specify a headerLeft
in the navigation options of the target screen, the title mysteriously disappears.
Sample project can be found here: https://github.com/beardwin/AndroidRNScreensBug
Expo 38.0.8
react-native-screens 2.9.0.
The app is basically as follows:
import React, { useEffect } from "react";
import { StackScreenProps } from "@react-navigation/stack";
import { createNativeStackNavigator } from "react-native-screens/native-stack";
import { Button, StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { enableScreens } from "react-native-screens";
enableScreens();
type NavigatorParams = {
Home: undefined;
PooFarts: undefined;
};
const HomeScreen = ({
navigation,
}: StackScreenProps<NavigatorParams, "Home">) => (
<View style={styles.screen}>
<Text>Home Screen</Text>
<Button
onPress={() => {
navigation.navigate("PooFarts");
}}
title="Pop a poo fart"
/>
</View>
);
const PooFartsScreen = ({
navigation,
}: StackScreenProps<NavigatorParams, "PooFarts">) => {
useEffect(() => {
navigation.setOptions({
title: "Fiddlesticks",
// uncomment below, and the title will no longer appear
// headerLeft: () => <Button title="Adios!" onPress={navigation.goBack} />,
});
}, [navigation]);
return (
<View style={styles.screen}>
<Text>Poo Farts</Text>
</View>
);
};
const Stack = createNativeStackNavigator<NavigatorParams>();
const Navigator = () => (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen
name="PooFarts"
component={PooFartsScreen}
options={{ stackPresentation: "modal" }}
/>
</Stack.Navigator>
);
export default function App() {
return (
<NavigationContainer>
<Navigator />
</NavigationContainer>
);
}
const styles = StyleSheet.create({
screen: {
...StyleSheet.absoluteFillObject,
justifyContent: "center",
alignItems: "center",
},
});
On Android
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Hide header in stack navigator React navigation
If you want only to hide the header on 1 screen you can do this by setting the screenOptions on the screen component...
Read more >createStackNavigator - React Navigation
Setting to null hides header. headerTitle . String, React Element or React Component used by the header. Defaults to scene title . When...
Read more >createStackNavigator - React Navigation - Netlify
Defaults to center on iOS and left on Android. # headerTitleAllowFontScaling. Whether header title font should scale to respect Text Size accessibility settings...
Read more >Components - NativeBase
Input values: Button, Title (Text). ... Icon ActionSheet (Android only) ... such as showing or hiding something in an app on click of...
Read more >React Native Configuring Header Bar - GeeksforGeeks
fontWeight: It is used to set the font style of the header title. ... headerLeft: It is used to add items on the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @beardwin, I ran into the same issue and solved it as follows, by using the
headerCenter
option and a helper method to create navigation options that can easily be reused. Trick is to set the title empty for Android and use theheaderCenter
option instead. For iOS the functionality can be kept as-is.Then you can use this method in your navigators like this:
Alright, the reason why it’s happening makes sense, it’s just that the title could probably be a separate property or something… Thanks for the speedy reply! I think I’ll just go ahead and try to replicate the original title and add a button next to it similarly to how it looks inside modals.