如何在抽屉标题添加元素-react-native

问题描述 投票:0回答:1

我是原生反应新手,我正在尝试将元素插入抽屉标题中,我的想法是从屏幕上删除标题并使用 onPress 创建一个新标题并添加两个以上元素,但我找不到属性为了这。感谢您阅读我的文章。

我的代码

<Drawer.Navigator
            drawerContent={props => <CustomDrawer {...props} />}
            screenOptions={{
                headerStyle: { backgroundColor: '#6A994E' },
                headerTitleStyle: { color: '#fff' },
                headerTintColor: '#fff',
                drawerLabelStyle: { marginLeft: -25, fontSize: 15 },
                drawerActiveBackgroundColor: '#6A994E',
                drawerActiveTintColor: '#fff',
                headerRight: (props) => { <HeaderComponent {...props} /> }
            }}
        >
            <Drawer.Screen name='Sales' component={SalesScreen} options={{ drawerIcon: SalesIcon}} />
            <Drawer.Screen name='Inventory' component={InventoryScreen} options={{ drawerIcon: InventoryIcon }} />
        </Drawer.Navigator>

样机

react-native navigation-drawer
1个回答
0
投票

只需使用

headerTitle
替换当前标题,并使用
headerRight
替换其他元素。像这样的东西:

screenOptions={{
...
  headerTitle: (props) => (
    <Pressable onPress={...}>
      <Text>New title</Text>
    </Pressable>
  ),
  headerRight: (props) => {
    return <HeaderComponent {...props} />;
  },
}}
© www.soinside.com 2019 - 2024. All rights reserved.