1. 20
    Add Bottom Tabs to a React Native App with React Navigation
    3m 4s

Add Bottom Tabs to a React Native App with React Navigation

InstructorChris Achard

Share this video with your friends

Send Tweet

Tabs are another popular navigation paradigm on mobile, so we’ll add tabs to the bottom of the screen, which will make it easy to switch between the primary screens of our application.

とうせいきょう
~ 6 years ago

For react-navigation v3, App.js should be

import React, { Component } from 'react';
import {
  createStackNavigator,
  createAppContainer,
  createBottomTabNavigator
} from 'react-navigation';
import Icon from 'react-native-vector-icons/FontAwesome'

import RestaurantList from 'components/RestaurantList';
import RestaurantInfo from 'components/RestaurantInfo';
import About from 'components/About';

const List = createStackNavigator({
  Home: { screen: RestaurantList },
  Info: { screen: RestaurantInfo }
}, {
  defaultNavigationOptions: {
    headerStyle: {
      backgroundColor: '#0066cc',
      color: '#fff'
    },
    headerTintColor: '#fff',
    headerTitleStyle: { color: '#fff' }
  }
});

const TabNavigator = createBottomTabNavigator({
  List: { screen: List },
  About: { screen: About }
}, {
  defaultNavigationOptions: ({ navigation }) => {
    return {
      tabBarIcon: ({ tintColor }) => {
        const route = navigation.state.routeName;
        console.log('route', route);
        const name = {
          'List': 'list',
          'About': 'info-circle'
        }[route]
        return <Icon name={name} color={tintColor} size={22} />
      },
      tabBarOptions: {
        activeBackgroundColor: '#E6F0FA'
      }
    }
  }
});

export default createAppContainer(TabNavigator);
Karstacian
~ 6 years ago

Thanks とうせいきょう

emekafredy
~ 5 years ago

Thanks とうせいきょう

Jayakrishnan JR
~ 5 years ago

The ** createBottomTabNavigator ** is moved to another package. Install it with yarn add react-navigation-tabs Then update the js file

import {createBottomTabNavigator} from 'react-navigation-tabs';

Then if you are getting an error null of something then cd ios pod install And restart the project again