I am using the functional approach with react-navigation v5.0.0, and I have a stack-navigator which contains:
App.js
<Stack.Screen
name="Profil"
component={Profile}
options={{
headerStyle: {
backgroundColor: '#2270b9'
},
headerTintColor: '#fff',
headerTitleStyle: {
color: 'white'
},
headerRight: () => (
<View style={{ flex: 1, flexDirection: 'row' }}>
<Ionicons
style={{ color: 'white', marginRight: 15, marginTop: 5 }}
size={32}
onPress={() => { _sendMessage(...) }} // <--- problem is here
name="ios-mail"
backgroundColor="#CCC"
/>
</View>
)
}}
/>
Profile component looks roughly like this:
Profile.js
export default function Profile({ route, navigation }) {
const { profile } = route.params;
return (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<ScrollView contentContainerStyle={styles.contentContainer}>
[...]
Now the problem is, Profile gets initialized with a payload object ("profile"), when the profile is opened:
Search.js / Visitors.js
navigation.navigate('Profil', { profile });
And the issue is, the send-button which is added in App.js needs the profile object which is passed to the Profile.js as route param, but it is not available in App.js.
How can I thus create the header button within Profile component, so I can access the profile object?