I have a component that returns a <Stack.Navigator> that contains a couple of screens. I also have a custom headerLeft element that executes a function on click. Now I am trying to hide the headerLeft if I am on the Test screen, but have it visible on all the others.
Before implementing my own back button, I just used this to hide the back button on the enterEmail screen:
<Stack.Screen
name="Test"
options={{ title: 'test', headerBackVisible: false }}
component={Test}
/>
But now that I'm using a custom element, this doesn't work.
const TestStack: FunctionComponent = () => {
const navigation = useNavigation();
const headerTitle = <Text>Log in</Text>;
return (
<Stack.Navigator
initialRouteName="Landing"
screenOptions={{
headerTitleAlign: 'center',
headerBackVisible: false,
headerLeft: () => <NavigationBackButton onPress={() => navigation.goBack()} />,
headerRight: () => <NavigationCloseButton onPress={() => navigation.navigate('Home')} />,
}}
>
<Stack.Screen options={{ headerShown: false }} name="Home" component={Home} />
<Stack.Screen
name="Test"
options={{ headerTitle: () => headerTitle }}
component={Test}
/>
</Stack.Navigator>
);
};