Change Color Of Active TabBarIcon React Native

2.5k Views Asked by At

Similar to this question, but I want to change the color of the icon as well - not just the text.

Here is the code in question:

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarOptions: {
    activeTintColor: '#6CC7BD',
    inactiveTintColor: '#CCCCCC',
  },
  tabBarIcon: ({focused}) => (
    <TabBarIcon
      focused={focused}
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${focused ? '' : '-outline'}`
          : 'md-information-circle'
      }
    />
  )
}

According to this thread on Github, I should try this:

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarOptions: {
    activeTintColor: '#6CC7BD',
    inactiveTintColor: '#CCCCCC',
  },

  tabBarIcon: ({focused}) => <TabBarIcon name={
    Platform.OS === 'ios'
      ? `ios-information-circle${focused ? '' : '-outline'}`
      : 'md-information-circle'
  } color={this.activeTintColor}/>
}

But the information circle is still grey: enter image description here

Also tried color={this.tabBarOptions.activeTintColor}, which caused an error:

enter image description here

Any other suggestions?

Edit - Also tried:

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarOptions: {
    activeTintColor: '#6CC7BD',
    inactiveTintColor: '#CCCCCC',
  },
  tabBarIcon: ({activeTintColor}) => (
    <TabBarIcon
      activeTintColor={activeTintColor}
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${activeTintColor ? '' : '-outline'}`
          : 'md-information-circle'
      }
      color={this.activeTintColor}
    />
  )
}
1

There are 1 best solutions below

0
On

did you try to add all the props:

tabBarIcon: ({focused, ...restProps}) => (
    <TabBarIcon
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${activeTintColor ? '' : '-outline'}`
          : 'md-information-circle'
      }
      focused={focused}
      {...restProps}
    />
  )