简体   繁体   English

如何使用反应导航向抽屉项目添加图标?

[英]How to add icons to drawer items using react-navigation?

None of the other questions/answers related to adding icons to drawer items have worked.与将图标添加到抽屉项目相关的其他问题/答案均无效。

Goal: use an image component as the drawer item's icon目标:使用图像组件作为抽屉项目的图标

Problem: using answers supplied to other questions doesn't work.问题:使用提供给其他问题的答案不起作用。 I get Reference Error: React is not Defined. The error is located at DrawerNavigatorItems at line {drawerIcon}我收到Reference Error: React is not Defined. The error is located at DrawerNavigatorItems at line {drawerIcon} Reference Error: React is not Defined. The error is located at DrawerNavigatorItems at line {drawerIcon}

DrawerNavigator route config code: DrawerNavigator 路由配置代码:

const drawerRouteConfig = {
    Inbox: {
        screen: InboxStack,
        navigationOptions: {
            drawerIcon: () => (
                <Image
                    source={require('../assets/img/white-inbox.png')}
                    style={{ height: width * 0.05, width: width * 0.05 }}
                    resizeMode={'contain'}
                />
            )
        }
    },
    Discover: DiscoverStack,
    Account: AccountStack,

};

How do I properly implement drawerItem icons?如何正确实现 drawerItem 图标?

My problem was that I hadn't imported React.我的问题是我没有导入 React。 fix: import React from 'react'修复: import React from 'react'

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM