question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with NativeBase tab bar mixed with react navigation

See original GitHub issue

29026121_1805530686148614_5213406963752239104_o 29063440_1805530846148598_6242474745552437248_o

We are getting these 2 issues when mix NativeBase tab bar and react navigation. Here is the code:

const MainTabBar = TabNavigator(
  {
    
   Saved: {screen: SavedScreen},
   Chat: {screen: ChatScreen},
    Profile: {screen: ProfileScreen},

  },
 
 {    
    tabBarPosition: 'bottom',
    swipeEnabled: false,
     tabBarComponent: props => {
      return (
        <Footer>
          <FooterTab>
            <Button
              vertical
              active={props.navigationState.index === 0}
              onPress={() => props.navigation.navigate("Saved")}>
              <Icon name="bowtie" />
              <Text>Lucy</Text>
            </Button>
            <Button
              vertical
              active={props.navigationState.index === 1}
              onPress={() => props.navigation.navigate("Profile")}>
              <Icon name="briefcase" />
              <Text>Nine</Text>
            </Button>
            <Button
              vertical
              active={props.navigationState.index === 2}
              onPress={() => props.navigation.navigate("Chat")}>
              <Icon name="headset" />
              <Text>Jade</Text>
            </Button>
          </FooterTab>
        </Footer>
       );
    }
  }
);

const Main = StackNavigator(
  {
   Signin: {screen: SigninScreen},
    Signup1: {screen: SignupScreen1},
     Welcome: {screen: WelcomeScreen},
     Settings: {screen: SettingsScreen},
    MainTab: {screen: MainTabBar}
  },
  {
    initialRouteName: "Signin",
    headerMode: "none",
  },
);

P.S you may noticed we used the code from your tutorial 😃 How these issues can be fixed? What is wrong in this code? Thanks in advance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
theZulqarnaincommented, Aug 2, 2019

if want to implement with react-navigation 3.0 with native-base 2.13 then below code will work.

 import { createBottomTabNavigator,createStackNavigator,createAppContainer } from 'react-navigation';
  import React from 'react';
  import { Button, Text, Icon, Footer, FooterTab } from 'native-base';

  import Home from './containers/Home';
  import CreateCase from './containers/CreateCase';
  import Profile from './containers/Profile';
  import Performance from './containers/Performance';

  const MainNavigator = createStackNavigator(
    {
        Home : {
            screen: Home,
            navigationOptions: {
              header: null,
            }
          },
      Create:  {
        screen: CreateCase,
        navigationOptions: {
          title: "Generate Case",
        }
      },
    },
    {
      initialRouteName: "Home"
    }
  );

  const Main = createBottomTabNavigator({
      Home: { screen: MainNavigator },
      Profile: { screen: Profile },
      Performance: {screen: Performance}
    },
    {
      tabBarComponent: props => {
        return (
          <Footer>
            <FooterTab>
              <Button
                vertical
                onPress={() => props.navigation.navigate('Home')}
              >
                <Icon name="bowtie" />
                <Text>Lucy</Text>
              </Button>
              <Button
                vertical
                onPress={() => props.navigation.navigate('Profile')}
              >
                <Icon name="briefcase" />
                <Text>Nine</Text>
              </Button>
              <Button
                vertical
              >
                <Icon name="headset" />
                <Text>Jade</Text>
              </Button>
            </FooterTab>
          </Footer>
        );
      }
    }
  );

  export default createAppContainer(Main);
3reactions
akhil-gacommented, Mar 12, 2018

@ArtyomBaykov tried a similar code. It was working fine with react-navigation

Code

import React from 'react';
import { Text, View } from 'react-native';
import { TabNavigator } from 'react-navigation';
import { Footer, FooterTab, Button, Icon, Text as NBText } from 'native-base'

class Lucy extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
                <Text>Lucy</Text>
            </View>
        );
    }
}

class Nine extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
                <Text>Nine</Text>
            </View>
        );
    }
}

class Jade extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
                <Text>Jade</Text>
            </View>
        );
    }
}

export default TabNavigator({
    Lucy: { screen: Lucy },
    Nine: { screen: Nine },
    Jade: { screen: Jade }
},
    {
        tabBarPosition: 'bottom',
        swipeEnabled: false,
        tabBarComponent: props => {
            return (
                <Footer>
                    <FooterTab>
                        <Button
                            vertical
                            active={props.navigationState.index === 0}
                            onPress={() => props.navigation.navigate("Lucy")}>
                            <Icon name="bowtie" />
                            <NBText>Lucy</NBText>
                        </Button>
                        <Button
                            vertical
                            active={props.navigationState.index === 1}
                            onPress={() => props.navigation.navigate("Nine")}>
                            <Icon name="briefcase" />
                            <NBText>Nine</NBText>
                        </Button>
                        <Button
                            vertical
                            active={props.navigationState.index === 2}
                            onPress={() => props.navigation.navigate("Jade")}>
                            <Icon name="headset" />
                            <Text>Jade</Text>
                        </Button>
                    </FooterTab>
                </Footer>
            );
        }
    });

Gif

footertab

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supporting safe areas
The rest of this guide gives more information on how to support safe areas in React Navigation. Hidden/Custom Header or Tab Bar​. Default...
Read more >
Native Base Tab Bar issue - react native
Trying to import tabs from native base fails with the following error: Element type is invalid: expected a string (for built-in components) but ......
Read more >
How to Combine Bottom Tabs, Top Tabs and a Hamburger ...
This guide will walk you through creating a simple application that contains bottom tab navigation, top tabs, and a hamburger menu to give...
Read more >
Components
The Components are constructed in pure React Native platform along with some JavaScript ... tabs, toast, drawer, thumbnail, spinner, layout, search bar etc....
Read more >
react-native-tab-view
API reference. The package exports a TabView component which is the one you'd use to render the tab view, and a TabBar component ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found