29

I'm using react-navigation v2 and react native vector icons.

I'm trying to add an icon in a react native tab navigator.

The icon shows up if its not in the tab navigator. The icon is not showing up in the tab navigator and I can't find a solid example of how to add an icon in a tab navigator.

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

import { createMaterialTopTabNavigator } from 'react-navigation'

import Home from '../HomePage.js'
import Profile s from '../ProfilePage.js'

import Icon from 'react-native-vector-icons/FontAwesome';

export const Tabs = createMaterialTopTabNavigator(
  {
    HomePage: {
      screen: Home,

      navigationOptions: {
        tabBarLabel:"Home Page",
        tabBarIcon: ({ tintColor }) => (
          <Icon name="home" size={30} color="#900" />
        )
      },
    },
    ProfilePage: {
      screen: Profile,
      navigationOptions: {
        tabBarLabel:"Profile Page",
        tabBarIcon: ({ tintColor }) => (
          <Icon name="users" size={30} color="#900" />
        )
      }
    },
  },

  {
    order: ['HomePage', 'ProfilePage'],
    tabBarOptions: {
      activeTintColor: '#D4AF37',
      inactiveTintColor: 'gray',
      style: {
        backgroundColor: 'white',
      }
    },
  },
)
Jeff Gu Kang
  • 4,749
  • 2
  • 36
  • 44
jrocc
  • 1,274
  • 2
  • 18
  • 48

4 Answers4

20

You can also simply add it with the help of Tab.Screen

First Import the icon from expo

import { Ionicons } from '@expo/vector-icons';

or choose any icons from here: https://icons.expo.fyi/

Then use it like this

<Tab.Screen
    name="Feed"
    component={Feed}
    options={{
      tabBarLabel: 'Home',
      tabBarIcon: ({ color, size }) => (
        <Ionicons name="home" color={color} size={size} />
      ),
    }}
  />
Lonare
  • 3,581
  • 1
  • 41
  • 45
15

Figured it out had to add

tabBarOptions: { 
   showIcon: true 
},

After this the icon showed.

ravibagul91
  • 20,072
  • 5
  • 36
  • 59
jrocc
  • 1,274
  • 2
  • 18
  • 48
  • 1
    Your code in the question worked for me without adding any other options when using `TabNavigator` – Pavindu Oct 04 '19 at 14:46
13

This works for me, without enable showIcon:true.

I am using Ionicons icon pack.

HomeScreen:{
    screen:HomeScreen,
    navigationOptions: {
      tabBarLabel:"Home",
      tabBarIcon: ({ tintColor }) => (
        <Icon name="ios-bookmarks" size={20}/>
      )
    },
  },
msalihbindak
  • 592
  • 6
  • 21
1

Setting activeTintColor also does the trick.

tabBarOptions: {
    activeTintColor: '#e91e63'
}
ravibagul91
  • 20,072
  • 5
  • 36
  • 59