简体   繁体   English

我如何向在本机中具有堆栈导航的抽屉式导航器项目添加图标

[英]how can i add icons to drawer navigator items that have stack navigation in react native

i want to add icons to drawer items which have separate stack navigation screens. 我想将图标添加到具有单独堆栈导航屏幕的抽屉项目中。 When i try to add drawer Icons to navigation options inside of the main screen, nothing show. 当我尝试将抽屉图标添加到主屏幕内的导航选项时,什么也没有显示。 Here's a snippet of my code 这是我的代码片段

const HomeScreenNav = createStackNavigator({
  main: {screen: Main },
  providers: { screen: Providers},
  providerProfile: { screen: ProviderProfile},
}, {
  initialRouteName: 'main',
})

Then my drawer navigation 然后我的抽屉导航

const AppDrawerNavigation = createDrawerNavigator({
   home: { screen: HomeScreenNav },
   appointments: {screen: Appointments}
}, {
   initialRouteName: 'home',
   drawerBackgroundColor: '#fff7fc',
   contentComponent: drawerComponent,
})

You have to add navigationOptions to the routes of your drawerNavigator. 您必须将navigationOptions添加到抽屉导航的路由中。 This is how you one can add icons and other components like text, label, title etc and customize your navigation drawer. 这是您可以添加图标和其他组件(如文本,标签,标题等)并自定义导航抽屉的方式。 Here's your modified code.: 这是修改后的代码:

    const AppDrawerNavigation = createDrawerNavigator({
         home: { screen: HomeScreenNav,
                 navigationOptions: {
                 drawerIcon: (
                      <Icon name={$YourIconName} size={24}
                          ..
                          //you can also add color and other Icon props here                        
                      />
                    ),
                  },
                },
         appointments: {screen: Appointments,
                         navigationOptions: {
                         drawerIcon: (
                              <Icon name={$YourIconName} size={24}
                                  ..
                               //you can also add color and other Icon props here                        
                              />
                           ),
                         }, 
                       }
     }, {
         initialRouteName: 'home',
         drawerBackgroundColor: '#fff7fc',
         contentComponent: drawerComponent,
     })

Below is the code, add it inside navigationOptions on how you can add customized text to your navigation drawer: 下面是代码,将其添加到navigationOptions内,以介绍如何将自定义文本添加到导航抽屉:

    ..
    drawer: {
            label: () => <Text>My Home</Text>
          },
    ..

Similarly, you can specify title to your header, where you wish to change the header title on selecting corresponding option in your drawer navigator. 同样,您可以在标题中指定标题,您希望在抽屉导航器中选择相应选项时更改标题。

    ..
    title:"My Home"
    ..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React native:如何让多个抽屉导航器链接指向同一个堆栈导航器中的屏幕 - React native: How can I have multiple drawer navigator links point to screens within the same stack navigator 使用堆栈导航器反应原生抽屉导航 - React native drawer navigation with stack navigator React Native中带抽屉和堆栈导航器的嵌套导航 - Nested Navigation with drawer and stack navigator in React Native 反应导航 - 反应原生 - 如何阻止嵌套在抽屉导航器内的堆栈导航器中的抽屉? - React navigation - react native - How to block drawer in Stack Navigator nested inside Drawer Navigator? 如何在React Native中在Drawer Navigator中动态添加项目? - How to dynamically add items in Drawer Navigator in react native? 我有一个使用react-navigation 3.3.0的堆栈导航器,并且我想为特定屏幕提供抽屉式导航 - I have a stack navigator using react-navigation 3.3.0 and I want to have a drawer navigation for a specific screen 使用 React Navigation,如何强制抽屉导航器弹出到堆栈顶部? - Using React Navigation, how can I force the drawer navigator to pop to the top of the stack? 如何使用反应导航向抽屉项目添加图标? - How to add icons to drawer items using react-navigation? 如何在现有项目的堆栈导航器中添加导航抽屉 - How can i add a navigation drawer inside a stack navigator in an already existing project React Navigation 5堆栈导航器和抽屉导航器一起 - React navigation 5 stack navigator and drawer navigator together
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM