【问题标题】:How to pass props in headerTitle inside options prop of a React Native Screen Component?如何在 React Native Screen Component 的 options 道具中传递 headerTitle 中的道具?
【发布时间】:2020-10-04 05:25:48
【问题描述】:

https://reactnavigation.org/docs/headers#replacing-the-title-with-a-custom-component

在此链接中,有一个示例代码(复制如下)。在 options prop 中,headerTitle 是一个接受 props 作为参数的函数。我们在哪里传递该道具,因为我们从未真正调用 headerTitle。是否有一些默认的道具被传递,我们正在将其重命名为道具?

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-native react-navigation


    【解决方案1】:

    你不能通过道具。 React Navigation 正在传递这些道具以供您在需要时使用。

    如果您查看here,您会看到该对象内部有哪些道具。

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 2020-11-20
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多