I followed the tutorial on this link https://callstack.github.io/react-native-paper/docs/guides/react-navigation/#adding-appbar for your reference.
I have a custom header AppHeader from React Native Paper. Below is the code:
import { Appbar } from 'react-native-paper';
const AppHeader = ({ navigation, back }) => {
const _goBack = () => navigation.pop();
const _handleProfile = () => navigation.navigate('Profile');
const _handleMore = () => console.log('Shown more');
return (
<Appbar.Header>
{back ? <Appbar.BackAction onPress={_goBack} /> : null}
<Appbar.Content title='This is my sample title' />
<Appbar.Action icon="account-circle-outline" onPress={_handleProfile} />
<Appbar.Action icon="dots-vertical" onPress={_handleMore} />
</Appbar.Header>
)
}
Then below is the code for the navigation on App.js:
import AppHeader from './components/AppHeader';
const App = () => {
return (
<PaperProvider theme={theme}>
<NavigationContainer theme={LightTheme}>
<Stack.Navigator
initialRouteName="Home"
screenOptions={{
header: (props) => <AppHeader {...props} />,
...TransitionPresets.FadeFromBottomAndroid,
}}
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
<Stack.Screen name="About" component={AboutScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
</Stack.Navigator>
</NavigationContainer>
</PaperProvider>
);
}
I have three different screen that uses the navigation header, how can I change the title (in this case This is my sample title
to the title that I want depending on the screen? For example change the title to Home
when on HomeScreen, About
on AboutScreen and so on.
Below are image for reference:
Home Screen
Details Screen