0

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

global.style.js

import { StyleSheet } from "react-native";

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

路由器.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 值。

有任何想法吗?

提前致谢!

4

1 回答 1

0

尝试添加到导航或按照react-navigation

tabBarOptions: {
  activeTintColor: 'green',
  inactiveTintColor: 'white',
  inactiveBackgroundColor:'green'
},
于 2019-04-20T05:45:40.153 回答