React-native-vector-icons: Color of the icon doesn't work well with react-navigation

Created on 18 Apr 2017  路  3Comments  路  Source: oblador/react-native-vector-icons

static navigationOptions = {
        tabBar: {
            label: 'Home',
            icon: ({tintcolor}) => (

                <Icon name="rocket" size={30}  color={tintcolor} />
            )
        },

label get the tintcolor ,but Icon still shows with its initial color,why?

Most helpful comment

It's still works.

Let create TabIcon component.

\\ TabIcon.js

import React, { PropTypes } from 'react';
import Icon from 'react-native-vector-icons/Ionicons';

const TabIcon = ({ focused, iconDefault, iconFocused, tintColor, size }) => {
    return (
        <Icon
            name={focused ? iconFocused : iconDefault}
            size={size}
            style={{ color: tintColor }}
        />
    );
};
TabIcon.propTypes = {
    focused: PropTypes.bool,
    iconDefault: PropTypes.string.isRequired,
    iconFocused: PropTypes.string.isRequired,
    tintColor: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string
    ]),
    size: PropTypes.number
};
TabIcon.defaultProps = {
    focused: false,
    tintColor: 'orange',
    size: 28
};

export default TabIcon;

Then import to your TabNavigator

import React from 'react';
import { TabNavigator, TabBarBottom } from 'react-navigation';
import TabIcon from '../path_to_tab_icon/TabIcon';
import TabHome from '../screens/TabHome';
import TabProfile from '../screens/TabProfile';

const RootNavigator = TabNavigator({
    TabHome: {
        screen: TabHome,
        navigationOptions: {
            title: 'Home',
            tabBarIcon: ({ focused, tintColor }) => (
                <TabIcon
                    iconDefault='ios-compass-outline'
                    iconFocused='ios-compass'
                    focused={focused}
                    tintColor={tintColor}
                />
            )
        }
    },
    TabProfile: {
        screen: TabProfile,
        navigationOptions: {
            title: 'Home',
            tabBarIcon: ({ focused, tintColor }) => (
                <TabIcon
                    iconDefault='ios-compass-outline'
                    iconFocused='ios-compass'
                    focused={focused}
                    tintColor={tintColor}
                />
            )
        }
    },
}, {
        tabBarOptions: {
            activeTintColor: 'black',
            inactiveTintColor: 'grey',
            activeBackgroundColor: 'white',
            inactiveBackgroundColor: 'yellow',
        },
    });

export default RootNavigator;

All 3 comments

I think you should post this issue in the react-navigation repo.

It's still works.

Let create TabIcon component.

\\ TabIcon.js

import React, { PropTypes } from 'react';
import Icon from 'react-native-vector-icons/Ionicons';

const TabIcon = ({ focused, iconDefault, iconFocused, tintColor, size }) => {
    return (
        <Icon
            name={focused ? iconFocused : iconDefault}
            size={size}
            style={{ color: tintColor }}
        />
    );
};
TabIcon.propTypes = {
    focused: PropTypes.bool,
    iconDefault: PropTypes.string.isRequired,
    iconFocused: PropTypes.string.isRequired,
    tintColor: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string
    ]),
    size: PropTypes.number
};
TabIcon.defaultProps = {
    focused: false,
    tintColor: 'orange',
    size: 28
};

export default TabIcon;

Then import to your TabNavigator

import React from 'react';
import { TabNavigator, TabBarBottom } from 'react-navigation';
import TabIcon from '../path_to_tab_icon/TabIcon';
import TabHome from '../screens/TabHome';
import TabProfile from '../screens/TabProfile';

const RootNavigator = TabNavigator({
    TabHome: {
        screen: TabHome,
        navigationOptions: {
            title: 'Home',
            tabBarIcon: ({ focused, tintColor }) => (
                <TabIcon
                    iconDefault='ios-compass-outline'
                    iconFocused='ios-compass'
                    focused={focused}
                    tintColor={tintColor}
                />
            )
        }
    },
    TabProfile: {
        screen: TabProfile,
        navigationOptions: {
            title: 'Home',
            tabBarIcon: ({ focused, tintColor }) => (
                <TabIcon
                    iconDefault='ios-compass-outline'
                    iconFocused='ios-compass'
                    focused={focused}
                    tintColor={tintColor}
                />
            )
        }
    },
}, {
        tabBarOptions: {
            activeTintColor: 'black',
            inactiveTintColor: 'grey',
            activeBackgroundColor: 'white',
            inactiveBackgroundColor: 'yellow',
        },
    });

export default RootNavigator;

@jszcl just made a typo it's tintColor not tintcolor.

This can be closed, there is no issue with react-navigation.

Was this page helpful?
0 / 5 - 0 ratings