React Native createBottomTabNavigator从常量添加自定义颜色

时间:2018-08-31 06:25:03

标签: react-native react-native-navigation react-native-stylesheet

我正在努力实现createBottomTabNavigator。我添加了 tabBarIcon ,我想使用在全局样式文件的 const 中定义的全局颜色,如下所示:

global.style.js

import { StyleSheet } from "react-native";

export const Colors = {
 ...
  orange: "#F59200",
 ...
};

Router.js

import React, { Component } from "react";
...

import { StackNavigator } from "react-navigation";
import { createBottomTabNavigator, BottomTabBar } from "react-navigation-tabs";
import Icon from "react-native-vector-icons/FontAwesome";
import Colors from "MyApp/app/config/global.style";
...
import HomeScreen from "../screens/HomeScreen";
...

export const Tabs = createBottomTabNavigator({
  HomeScreen: {
    screen: HomeScreen,
    navigationOptions: () => ({
      tabBarLabel: "My Home Screen",
      tabBarIcon: ({ tintColor }) => (
        // color={Colors.orange} does not work here 
        <Icon name="rocket" color={Colors.orange} size={24} />
      )
    })
  },
...

我发现了一堆示例,这些示例演示了如何直接添加颜色,该方法有效:

HomeScreen: {
        screen: HomeScreen,
        navigationOptions: () => ({
          tabBarLabel: "My Home Screen",
          tabBarIcon: ({ tintColor }) => (
            <Icon name="rocket" color="#F59200" size={24} />
          )
        })
      }

但是我想知道是否有一种方法可以传递 const Colors 值。

有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试添加到导航中,或遵循react-navigation

tabBarOptions: {
  activeTintColor: 'green',
  inactiveTintColor: 'white',
  inactiveBackgroundColor:'green'
},