Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer' ?

See original GitHub issue

Hello! I am trying to use this but this is the error I get: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer' ?

Here is my code for my TabNavigator:

import React from "react";
import routes from "./routes";
import {View, Text, TouchableOpacity, Dimensions, StyleSheet, Image} from 'react-native'
import HomeButton from "./HomeButton";
import CardsScreen from "../screens/CardsScreen";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import AccountNavigator from "./AccountNavigator";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import defaultStyles from "../config/defaultStyles";
import HomeNavigator from "./HomeNavigator";
import { Feather } from '@expo/vector-icons'; 
import { FontAwesome5 } from '@expo/vector-icons'; 
import { MaterialIcons } from '@expo/vector-icons'; 
import { AnimatedTabBarNavigator } from "react-native-animated-nav-tab-bar";

const Tab = AnimatedTabBarNavigator();
const window = Dimensions.get("window")

const CustomTabBar = ({state, descriptors, navigation}) => {
  let button;
  return(
    <View style={styles.bottomContainer}>
      {state.routes.map((route, index) => {
        const clicked = state.index === index;
        {route.name==="Home" ? button=
        <TouchableOpacity key={route.name}  onPress={()=>{
          if (!clicked) {
            navigation.navigate(route.name);
          }
        }} 
        style={{flex: 1}}
        accessibilityRole="button"
        accessibilityState={clicked ? { selected: true } : {}}
        delayPressIn={0}
        >
            <View style={styles.homeButton}>
              <Feather name="home" size={35} color="white" /> 
            </View>
        </TouchableOpacity> 
        : 
        button=
        <TouchableOpacity key={route.name} onPress={()=>{
          if (!clicked) {
            navigation.navigate(route.name);
          }
        }} 
        style={{flex: 1}}
        accessibilityRole="button"
        accessibilityState={clicked ? { selected: true } : {}}
        delayPressIn={0}
        >
          <View style={styles.sideButton}>
            {route.name==="Account"? <FontAwesome5 name="user-circle" size={window.width*0.09} color={defaultStyles.colors.primary} />:
            <MaterialIcons name="credit-card" size={window.width*0.104} color={defaultStyles.colors.primary} />
            }
          </View>
        </TouchableOpacity>}
        return button;
      })}
    </View>
  )
}

const TabNavigator = (props) => (
    <>
      <Tab.Navigator
        initialRouteName="Home"
        barStyle={{ backgroundColor: defaultStyles.colors.white }}
        activeColor={defaultStyles.colors.white}
        tabBar={(props) => <CustomTabBar {...props}/>}
      >
        <Tab.Screen
          name="Cards"
          component={CardsScreen}
          // options={{
          //   tabBarIcon: ({ color, size }) => (
          //     <MaterialCommunityIcons
          //       name="credit-card-outline"
          //       size={27}
          //       color={color}
          //     />
          //   ),
          // }}
        />
        <Tab.Screen
          name="Home"
          component={HomeNavigator}
          // options={({ navigation }) => ({
          //   tabBarButton: () => (
          //     <HomeButton onPress={() => props.navigation.navigate(routes.HOME)} />
          //   ),
          //   headerShown: false,
          // })}
        />
  
        <Tab.Screen
          name="Account"
          component={AccountNavigator}
          // options={{
          //   tabBarIcon: ({ color, size }) => (
          //     <MaterialCommunityIcons name="account" size={27} color={color} />
          //   ),
          // }}
        />
      </Tab.Navigator>
    </>
  );

  const styles = StyleSheet.create({
    bottomContainer: {
      flexDirection: 'row', 
      alignItems: 'center',
      bottom: window.height*0.05,
      borderRadius: 25,
      backgroundColor: 'white',
      marginHorizontal: window.width*0.07,
      height: window.height*0.069,
      shadowColor: defaultStyles.colors.primary,
      shadowRadius: 15,
      //shadowOffset: {width: 4, height: 4},
      shadowOpacity: 0.3
    },
    homeButton: {
      width: window.width*0.213,
      height: window.width*0.213,
      backgroundColor: defaultStyles.colors.primary,
      alignSelf: 'center',
      borderRadius: window.width*0.213/2,
      alignItems: 'center',
      justifyContent: 'center',

    },
    homeIcon: {
      height: 32,
      width: 37
    },
    sideButton: {
      justifyContent: 'center',
      alignItems: 'center',
    }
  })

  export default TabNavigator;

On my App.js, I am indeed wrapping it:

      <NavigationContainer theme={NavigationTheme.DefaultAppTheme}>
        <OverflowMenuProvider>
          <AuthNavigator />
        </OverflowMenuProvider>
      </NavigationContainer>

I know that’s not the issue because when I replace const Tab = AnimatedTabBarNavigator(); with const Tab = createBottomTabNavigator(); it works just fine. I also tried it using the example provided in the documentation with a really simple navigator and same error.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
torgeadelincommented, Jan 29, 2021

This issue should now be fixed with the latest react-navigation version ^5.9.0

1reaction
pasteancommented, Nov 27, 2020

works at 5.1.6

@TheAlmightyThor make sure to run the bundler with --reset-cache

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Couldn't register the navigator. Have you wrapped your ...
I would like to notice, that NavigationContainer is a necessary element for the stack navigator. It doesn't work without it. – Mikhail Barinov....
Read more >
Couldn't register the navigator. Have you wrapped your app ...
I'm getting the error: Error: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'? and then the app crashes.
Read more >
fear48/react-native - Gitter
Error : Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'? but I am wrapping the code with a container. here...
Read more >
NavigationContainer | React Navigation
The NavigationContainer is responsible for managing your app state and linking your top-level navigator to the app environment.
Read more >
Error: Couldn't register the navigator. Have you wrapped your ...
Coding example for the question Error: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?-React Native.
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