https:/reactnavigation.orgdocsheaders#replacing-the-title-with-a-custom-component。
在这个链接中,有一个示例代码(复制如下)。在options prop里面,headerTitle是一个接受props作为参数的函数。我们在哪里传递这个prop,因为我们从来没有真正调用过headerTitle。是否有一些默认的prop被传递了,我们把它重命名为props?
function LogoTitle() {
return (
<Image
style={{ width: 50, height: 50 }}
source={require('@expo/snack-static/react-native-logo.png')}
/>
);
}
function StackScreen() {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ headerTitle: props => <LogoTitle {...props} /> }}
/>
</Stack.Navigator>
);
}
你不能通过道具。React Navigation 是通过这些道具让你在需要的时候使用它。
如果你看 此处 你会看到该对象里面有什么道具。