【发布时间】:2020-04-09 11:41:51
【问题描述】:
我正在使用react-navigation v5.0.0 的函数式方法,并且我有一个堆栈导航器,其中包含:
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 组件大致如下:
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}>
[...]
现在的问题是,Profile 在打开配置文件时使用有效负载对象(“配置文件”)进行初始化:
Search.js / Visitors.js
navigation.navigate('Profil', { profile });
问题是,App.js 中添加的发送按钮需要作为路由参数传递给Profile.js 的配置文件对象,但在App.js 中不可用。
如何在Profile 组件中创建标题按钮,以便访问配置文件对象?
【问题讨论】:
标签: javascript react-native header navigation react-navigation