简体   繁体   English

createBottomTabNavigator的标签未显示-React Native

[英]Label of createBottomTabNavigator not showing - React Native

So I pulled one of my react native projects from a few months ago and While using it I discovered that TabNavigator was deprecated. 因此,我从几个月前TabNavigator了我的一个响应本机项目,并且在使用它时,我发现不推荐使用TabNavigator So instread I am now using createBottomTabNavigator like they suggested. 因此,按照我的建议,我现在正在使用createBottomTabNavigator It seems to work out of the box, but for some reason my labels are not showing, only the icons in the tabs. 它似乎开箱即用,但是由于某些原因我的标签没有显示,仅显示选项卡中的图标。

I was looking at the docs and it was saying it is actually default true for showing the label. 我在看文档,说是显示标签实际上是默认true For some reason the label just won't show up. 由于某种原因,标签将不会显示。 Also tried to set the showLabel to true but that didn't do anything else. 还尝试将showLabel设置为true,但这没有做任何其他事情。 Someone with the same problem that got a fix? 有人遇到相同问题的解决方法?

My code 我的密码

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

// Icons for tabs
import I from 'react-native-vector-icons/MaterialCommunityIcons';

// Navigation dep
import { createBottomTabNavigator, createStackNavigator } from 'react-navigation';

// Custom components/screens
import HomeScreen from './screens/HomeScreen'
import FavoritesScreen from './screens/FavoritesScreen'
import AccountScreen from './screens/AccountScreen'

// Custom styles
import HeaderBar from './styles/HeaderBar'

// Tabs navigation
const HomeStack = createStackNavigator({
    Home: HomeScreen
});

const FavoritesStack = createStackNavigator({
    Favorites: FavoritesScreen
});

const AccountStack = createStackNavigator({
    Account: AccountScreen
});

export default createBottomTabNavigator(
    {
        Home: HomeStack,
        Favorites: FavoritesStack,
        Account: AccountStack,
    },
    {
        navigationOptions: ({ navigation }) => ({
            tabBarIcon: ({ focused, tintColor }) => {

                const { routeName } = navigation.state;
                let iconName;
                if (routeName === 'Home') {
                    iconName = `tag${focused ? '' : '-outline'}`;
                } else if (routeName === 'Favorites') {
                    iconName = `heart${focused ? '' : '-outline'}`;
                } else {
                    iconName = `account-box${focused ? '' : '-outline'}`;
                }

                return <I name={iconName} size={25} color={tintColor} />;
            },
            tabBarLabel: () => {
                const { routeName } = navigation.state;
                return routeName.toUpperCase();

            }
        }),

        tabBarOptions: {
            activeTintColor: '#E95736',
            inactiveTintColor: 'gray',
            labelStyle: {
                fontSize: 9,
                fontFamily: 'Rubik-Medium'
            },
            style: {
                backgroundColor: '#FAF8F8',
                borderTopWidth: 0.5
            },
        },
    }

); );

I think the issue is related to tabBarLabel and I believe the problem will fix itself if you remove that bit. 我认为该问题与tabBarLabel有关,并且我相信如果删除该位,该问题将自行解决。 You can easily achieve the same effect by just making the label text upper case where you declare the route. 您只需将标签文本声明为大写字母即可轻松实现相同的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM