选择和未选择状态的反应导航中的不同tabBar图标?

Posted

技术标签:

【中文标题】选择和未选择状态的反应导航中的不同tabBar图标?【英文标题】:Different tabBar icons in react navigation for selected and unselected state? 【发布时间】:2017-06-21 06:24:45 【问题描述】:

我正在使用 react native 中的 react 导航设置标签栏。我无法为选中/未选中状态设置多个标签栏图标。任何参考或文档都会有所帮助?

【问题讨论】:

【参考方案1】:

tabBarIcon 回调为您提供 focused 变量。

static navigationOptions = 
    tabBarLabel: 'Home',
    tabBarIcon: ( focused ) => 
        const image = focused 
        ? require('../active.png') 
        : require('../inactive.png')
        return (
            <Image 
                source=image
                style=styles.tabIcon
            />
        )
    

【讨论】:

【参考方案2】:

您可以根据activeTintColor / inactiveTintColor更改图标

static navigationOptions = 
    tabBarLabel: 'Notifications',
    tabBarIcon: ( tintColor ) => (tintColor == '#e91e63' ?
      <Image
        source=require('./activeIcon.png')
        style=[styles.icon, tintColor: tintColor]
      />
      :
      <Image
        source=require('./inactiveIcon.png')
        style=[styles.icon, tintColor: tintColor]
      />
    ),
    tabBarOptions: 
        activeTintColor: '#e91e63',
    

;

即使你不使用 tint 颜色,你也可以这样做。

【讨论】:

以上是关于选择和未选择状态的反应导航中的不同tabBar图标?的主要内容,如果未能解决你的问题,请参考以下文章

TabBar 图标对选择的反弹效果就像 Swift 中的 Twitter 应用程序

反应状态没有更新

微信小程序01:底部菜单(tabBar)

Axure RP从入门到精通(五十一)APP案例 - 底栏

从嵌套的 StackNavigator 中隐藏 TabBar 的反应导航屏幕

快速使用标签栏上的不同图标