【问题标题】:Dynamic title in React Native Elements Header componentReact Native Elements Header 组件中的动态标题
【发布时间】:2021-01-03 12:25:08
【问题描述】:

我正在使用https://reactnativeelements.com/docs/header

我也在使用 react native 标签https://reactnavigation.org/docs/bottom-tab-navigator/

    <Drawer
    ref={(ref) => this._drawer = ref}
    type="overlay"
    content={< MyDrawer />}
    tapToClose={true}
    open={false}
    openDrawerOffset={0.5}
    captureGestures={true}
    styles={drawerStyles}
    // tweenHandler={Drawer.tweenPresets.parallax}
    tweenHandler={(ratio) => {
      return {
        mainOverlay: { opacity: ratio / 1.5, backgroundColor: 'black' }
      }
    }}
    panOpenMask={0.1} >
    <SafeAreaProvider>
      <Header
        leftComponent={
          <View>
            <TouchableOpacity onPress={() => this.calendarClick()}>
              <Ionicons name="calendar-outline" size={24} />
            </TouchableOpacity>
          </View>
        }
        centerComponent={{ text: "DYNAMIC_TITLE_HERE", style: { color: '#000', fontWeight: "bold", fontSize: 18, marginTop: 3 } }}
        rightComponent={<Ionicons name="cloud-upload-outline" size={24} />}
      />
      <NavigationContainer>
        <Tab.Navigator
          screenOptions={({ route }) => ({
            tabBarIcon: ({ focused, color, size }) => {
              let iconName = "ion-md-help";

              if (route.name === 'Home') {
                iconName = focused
                  ? 'ios-information-circle'
                  : 'ios-information-circle-outline';
              } else if (route.name === 'Settings') {
                iconName = focused ? 'ios-list-box' : 'ios-list';
              }

              // You can return any component that you like here!
              return <Ionicons name={iconName} size={size} color={color} />;
            },
          })}
          tabBarOptions={{
            activeTintColor: '#2B95DA',
            inactiveTintColor: 'gray',
          }}>

          <Tab.Screen
            name="Targets"
            component={TargetsScreen}
            options={{
              tabBarIcon: ({ color }) => <Ionicons name="rocket" color={color} size={24} />
            }}
          />

          <Tab.Screen
            name="Settings"
            component={SettingsScreen}
            options={{
              tabBarIcon: ({ color }) => <Ionicons name="settings" color={color} size={24} />,
            }} />

        </Tab.Navigator>
      </NavigationContainer>
      <StatusBar barStyle="dark-content" />
    </SafeAreaProvider>
  </Drawer >

我没有发现如何动态替换 ->centerComponent 中的 DYNAMIC_TITLE_HERE。有什么想法吗?

【问题讨论】:

    标签: react-native header react-native-elements


    【解决方案1】:

    确保在导航到动态标题时将其传递到屏幕。

    然后你可以将路由 obj 传递给你的 header 并从 route.params 中获取标题

    【讨论】:

      猜你喜欢
      • 2020-03-12
      • 2022-10-25
      • 2020-07-02
      • 2018-11-09
      • 2018-10-09
      • 1970-01-01
      • 2023-01-01
      • 1970-01-01
      • 2022-06-22
      相关资源
      最近更新 更多