GithubHelp home page GithubHelp logo

torgeadelin / react-native-animated-nav-tab-bar Goto Github PK

View Code? Open in Web Editor NEW
893.0 9.0 101.0 22.48 MB

A simple and customisable React Native component that implements an animated bottom tab bar for React Navigation.

License: MIT License

JavaScript 3.63% Java 18.66% Ruby 5.89% Objective-C 5.91% TypeScript 63.97% Objective-C++ 1.94%

react-native-animated-nav-tab-bar's Introduction

npm version contributions welcome HitCount npm

react-native-animated-nav-tab-bar

A simple and customizable React Native component that implements an animated bottom tab bar for React Navigation v6.

  • 60FPS
  • Support for iPhoneX
  • Lots of customization
  • Bottom Tab Bar Floating style

๐Ÿ“† Updates / Changelog

Changelog.md

Animation Preview

Customization Preview

config1.png

Other possible Customizations

Tab Bar Icons

Layout

Let's get to know you!

๐Ÿ‘‹ If your app is deployed to AppStore/GooglePlay and you're using this package, send me a DM on Twitter @torgeadelin

Prerequisites

In order to use the component, you need to have React Navigation v6 installed. You also need styled-components.

Installation

If using yarn

yarn add react-native-animated-nav-tab-bar

If using npm

npm install react-native-animated-nav-tab-bar

Usage

Notice

If you updated the package to a new version, don't forget to run npm run start -- --reset-cache to have the latest version.

Import

// Javascript
import { AnimatedTabBarNavigator } from "react-native-animated-nav-tab-bar";
// Typescript
import {
  AnimatedTabBarNavigator,
  DotSize, // optional
  TabElementDisplayOptions, // optional
  TabButtonLayout, // optional
  IAppearanceOptions // optional
} from 'react-native-animated-nav-tab-bar'

Initialize

Then create a navigator using the navigation builder that you imported, and create your navigation! Look at the example below.

...

const Tabs = AnimatedTabBarNavigator();

export default () => (
  <Tabs.Navigator
    // default configuration from React Navigation
    tabBarOptions={{
      activeTintColor: "#2F7C6E",
      inactiveTintColor: "#222222"
    }}
  >

    // Home Screen
    <Tabs.Screen name="Home" component={Home} />

    // Other screens go here.
    ...

  </Tabs.Navigator>
)

Add Icons

If you'd like to add icons to your Bottom Navigation you can use react-native-vector-icons. Look at an example of how to add icons to your tab bar.

Example

import Icon from 'react-native-vector-icons/Feather';

...

export default () =>
  <Tabs.Navigator
    tabBarOptions={{
      activeTintColor: "#2F7C6E",
      inactiveTintColor: "#222222"
    }}
  >
    <Tabs.Screen
      name="Home"
      component={Home}
      options={{
        tabBarIcon: ({ focused, color, size }) => (
            <Icon
                name="Home"
                size={size ? size : 24}
                color={focused ? color : "#222222"}
                focused={focused}
                color={color}
            />
        )
      }}
    />
    </Tabs.Navigator>

...

Documentation

The navigation component takes two main props which help you customize your navigation. tabBarOptions is the default prop from React Navigation which you can use to specify different tint colors and more (see available options below). for all the details. The second prop is appearance. Here you'll be able to adjust several properties of the tab bar as you wish. See the available properties above.

  • tabBarOptions

    • โœ…activeTintColor - Label and icon color of the active tab item.
    • โœ…inactiveTintColor - Label and icon color of the inactive tab item.
    • โœ…activeBackgroundColor - Background color of the active tab item.
    • โœ…tabStyle - Style object for the tab wrapper (Note! it overrides the properties in appearance prop (see below).
    • โœ…labelStyle - Style object for the tab label text.
  • appearance

    • โœ…topPadding (default: 20) - Space between the tab button and the wrapper (top)

    • โœ…horizontalPadding (default: 20) - Vertical space between for the tab buttons

    • โœ…tabBarBackground (default: "white") - Background color for the wrapper that contains the navigation tabs

    • โœ…shadow (default: true) - If set to true, the wrapper has a light shadow

    • โœ…activeTabBackgrounds - Array of hex colours for the background of each tab when active. (if not specified, falls back to the activeBackgroundColor from tabBarOptions)

    • โœ…activeColors - Array of hex colours for the tint of each tab when active. (if not specified, falls back to the activeTintColor from tabBarOptions)

    • โœ…floating (default: false) - If set to true, the nav bar will float on top of the current screen. Look at examples above.

    • โœ…whenActiveShow (default: "both") Configure the appearance of the active tab. Available values both, label-only, icon-only.

    • โœ…whenInactiveShow (default: "icon-only") Configure the appearance of the inactive tabs. Available values both, label-only, icon-only.

    • โœ…tabButtonLayout (default: "horizontal") Configure the layout of the tab button. Available values vertical, horizontal.

    • โœ…dotCornerRadius (default: 100) Corner radius for the active background / dot.

    • โœ…dotSize (default: "medium") Size of dot for the active tab. Available values small, medium, large.

    Note! Make sure you reload your view after changing the props. The animation might be stuck while changing them dynamically.

Troubleshooting

  • My tab doesn't reflect the tabStyle object when I set paddingTop. Solution: You must provide the same value for paddingTop in both tabStyle object and topPadding property from appearance. This is due to the fact that the dot / active background uses position absolute, and the parent's padding top does not affect it.
  • My appearance prop style doesn't apply. Solution: Up until version 3.1.2 there was a typo with the appearance prop. (Instead of appearance it was appearence). It has been fixed in 3.1.3 and you should make sure you're using the right spelling too if you update to 3.1.3.

Contributing

Pull requests are always welcome! Feel free to open a new GitHub issue for any changes that can be made.

If you raise an issue, please add proper steps to reproduce it and proper logs. Thanks!

Working on your first Pull Request? You can learn how from this free series How to Contribute to an Open Source Project on GitHub

Author

Catalin Torge @torgeadelin

License

MIT

react-native-animated-nav-tab-bar's People

Contributors

andresain123 avatar basurahan avatar dependabot[bot] avatar fr3fou avatar gthrm avatar holdmypotion avatar imarem avatar kstolk avatar kubanac95 avatar mayconpaivac avatar sconaway avatar torgeadelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-animated-nav-tab-bar's Issues

showing error

I am getting error while making the tab bar and i don't understand how to remove it.
image

Render method error

Hello, I tried this library but I can't get this to work. Can you help me?

`Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of TabBarElement.

This error is located at:
in RCTView (at View.js:34)
in View (at createAnimatedComponent.js:165)
in AnimatedComponent (at createAnimatedComponent.js:215)
in ForwardRef(AnimatedComponentWrapper) (at TouchableOpacity.js:224)
in TouchableOpacity (at TouchableOpacity.js:302)
in ForwardRef (created by Context.Consumer)
in StyledNativeComponent (created by Styled(Component))
in Styled(Component) (at TabBarElement.js:337)
in RCTView (at View.js:34)
in View (created by Context.Consumer)
in StyledNativeComponent (created by Styled(View))
in Styled(View) (at TabBarElement.js:415)
in RCTView (at View.js:34)
in View (at TabBarElement.js:414)
in TabBarElement (at AnimatedTabBarNavigator.js:49)
in BottomTabNavigator (at Router.js:17)
in RouterWithTab (at App.js:17)
in RNCSafeAreaProvider (at SafeAreaContext.tsx:74)
in SafeAreaProvider (at App.js:16)
in EnsureSingleNavigator (at BaseNavigationContainer.tsx:409)
in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91)
in ThemeProvider (at NavigationContainer.tsx:90)
in ForwardRef(NavigationContainer) (at App.js:15)
in App (created by ExpoRoot)
in ExpoRoot (at renderApplication.js:45)
in RCTView (at View.js:34)
in View (at AppContainer.js:106)
in RCTView (at View.js:34)
in View (at AppContainer.js:132)
in AppContainer (at renderApplication.js:39)

Stack trace:
node_modules\react-native\Libraries\LogBox\LogBox.js:148:8 in registerError
node_modules\react-native\Libraries\LogBox\LogBox.js:59:8 in errorImpl
node_modules\react-native\Libraries\LogBox\LogBox.js:33:4 in console.error
node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
node_modules\react-native\Libraries\Core\ExceptionsManager.js:104:6 in reportException
node_modules\react-native\Libraries\Core\ExceptionsManager.js:171:19 in handleException
node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
node_modules\expo-error-recovery\build\ErrorRecovery.fx.js:9:32 in ErrorUtils.setGlobalHandler$argument_0
node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
node_modules\regenerator-runtime\runtime.js:293:29 in invoke
node_modules\regenerator-runtime\runtime.js:63:36 in tryCatch
node_modules\regenerator-runtime\runtime.js:154:27 in invoke
node_modules\regenerator-runtime\runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue
[native code]:null in flushedQueue
[native code]:null in invokeCallbackAndReturnFlushedQueue
...`

Open modal

Hi, this is an awsome component. would it be possible to extend the tab screens to be configured like react native navigation tabbar?

either provide away to do
options={{
tabBarButton: (props) => (
<TouchableOpacity
{...props}
onPress={() => navigation.navigate('ModalView')}
/>
),
}}

Or

listeners={({navigation, route}) => ({
tabPress: (e) => {
// Prevent default action
e.preventDefault();

        // Do something with the `navigation` object
        navigation.navigate('ModalView');
      },
    })}

Bottom tabs overlay

Hi and thanks for the library, currently i'm using version 3.0.3 and followed the example code that provided, and this happened.
(Currently temp walkaround which is head to node_modules/react-native-aniamted-nav-tab-bar/src/TabBarElement, change the overlayStyle to flex:0.1 & current screen to flex:0.9 will solved the problem.)
Screenshot_1597215426

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

I use TypeScript, and install follow your docs.
My import:

Screen Shot 2020-09-29 at 10 53 22 AM

My Tab.Navigator:

Screen Shot 2020-09-29 at 11 03 57 AM

After, i wrapp it, and pass to 2 stack is AuthStack and AppStack to check user loggin.

Screen Shot 2020-09-29 at 11 04 52 AM

In App.tsx, my return:
Screen Shot 2020-09-29 at 11 05 31 AM

-> However, it through error: Couldn't register the navigator. Have you wrapped your app with 'NavigationContainer'?
But I wrapper it in App.tsx, How to solve this problem ?
"react-native": "0.63.2",
"react-native-animated-nav-tab-bar": "^3.0.4",
"@react-navigation/native": "^5.1.4",
Tks your pretty lib.

fontFamily not taking effect in labelStyle property of tabBarOptions

I want to change the fontFamily of the tab label to match my entire app. Unfortunately its not taking effect.
Here is my tabBarOptions

{
       activeTintColor: 'white',  
       inactiveTintColor: 'gainsboro',  
       activeBackgroundColor: 'purple',  
       labelStyle: {  
                   fontFamily: 'Montserrat-Regular',  
                   color: 'white'  
       }  
 }

Tab item with long title

I have two concerns for the layout with reference to the screen cap.
Screenshot 2020-08-07 at 12 47 27 AM

  1. How to adjust the space between the text and the icon?
  2. How to add more padding for the title ending by squeezing the space between the subsequent icons

Add badge to icon bottom tabbar

Hmmm.
Is there any way to add badge to bottom tab icon. tks you.
I can custom when focus tab. But it not focused, I can't
Screen Shot 2020-10-23 at 2 12 28 PM

How to decrease padding between left side to icon and rightside to text and increase the tab height

i was trying to decrease padding between the icon and left side of icon and text and right side of text and tring to increase the height of tab which is a bit difficult to achieve. tabBarOptions is not at all working.

const HomeScreenTab = createMaterialTopTabNavigator(
{
Home: HomeStack,
Aiyoooo: DiscoverStack,
Images: ImagesStack,
Profie: ProfileStack,
},{
tabBarOptions: {
labelStyle: {
padding: 5
},
tabStyle: {
height: 90
},
iconStyle: {
padding: 80,
},
swipeEnabled: false,

          },
        tabBarComponent: props => <TabBar
            activeColors={'#fff'} // or activeColors={'#e6b580'}
            activeTabBackgrounds={'#4291E2'} // or activeTabBackgrounds={'#ede7e6'}
            {...props}
        />,
            animationEnabled: false,
            headerMode: "none",
            navigationOptions: {
            gesturesEnabled: false
            }

this is not at all working for me. even the colors are not updating

i can't customize tab-bar wirh apperance

import { NavigationContainer } from "@react-navigation/native";
import { AnimatedTabBarNavigator } from "react-native-animated-nav-tab-bar";
import { Text, View } from "react-native";
import React from "react";

const Tabs = AnimatedTabBarNavigator();

function home() {
  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text> Home Screen </Text>
    </View>
  );
}

function friend() {
  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text> firend Screen </Text>
    </View>
  );
}

const App = () => {
  return (
    <NavigationContainer>
      <Tabs.Navigator
        tabBarOptions={{
          activeTintColor: "black",
          inactiveTintColor: "black",
          tabBarBackGround: "",
        }}
        apperance={{
          horizontalPadding: 10,
          tabBarBackground: "black",
          floating: true,
          dotCornerRadius: 100,
          whenActiveShow: "both",
          whenInactiveShow: "label-only",
          shadow: false,
          dotSize: 100,
          tabButtonLayout: "horizontal",
        }}
      >
        <Tabs.Screen name="Home" component={home} />
        <Tabs.Screen name="Friend" component={friend} />
      </Tabs.Navigator>
    </NavigationContainer>
  );
};

export default App;

i am using expo and just made a simple example
The custom doesn't work for some reason.
I think I did something wrong because I'm not used to navigation. Can you help me?

KakaoTalk_20210116_182456988

issue with createNativeStackNavigator on iOS

When using createNativeStackNavigator from react-native-screens/native-stack
it seems the animated tab bar overlay is on top of everything and any buttons placed on the screens are not interactive.

I noticed when enableScreens() is called the issue starts appearing.

On Android is working fine.

Can you make it smoother for Android?

I've checked out this for both iOS and Android and it's working perfectly on iOS but on Android it's lagging on every touch to tab button.
Could you fix this?

useScrollToTop doesnt work

if I used createBottomTabNavigator(), useScrollToTop work normally
"react-native": "0.63.2",
"react-native-animated-nav-tab-bar": "^3.0.4",
"@react-native-community/masked-view": "^0.1.9",
"@react-navigation/bottom-tabs": "^5.2.7",
"@react-navigation/native": "^5.1.6",
"@react-navigation/stack": "^5.2.11",

How to gone icon when any tab is selected?

Right now, when we select any tab then the icon and text both are visible but is it possible that we only show the text when the tab is selected otherwise only show the icon?

Error - Can't find variable: HandleBackPress

Hi Bro, i'm facing this error - Can't find variable: HandleBackPress, and it's fixed by adding 'const' (at TabBarElement.js: 115).
const handleBackPress = () => { animation(animatedPos).start(() => { updatePrevPos(); }); };

Animation transition not smooth

Hi,

I'm using react-navigation 5 on Expo with a floating tab layout

During the first couple of clicks the animation is not smooth, it looks like it moves a little bit, gets stuck and then completes the move the the other tab.

After the first few animation everything runs smoothly.

Is there any specific config that I can use like to modify ease, speed of transition or similar

Thanks

Warning From Icon and TabBar component

I am getting following warnings while using Icon with TabBar component
Screenshot 2019-11-09 at 8 56 29 AM
Screenshot 2019-11-09 at 8 56 13 AM

Here's associated ways i tried-
NavigationOptions -

    Settings: {
      screen: SettingsNavigator,
      navigationOptions: {
        tabBarIcon: ({ focused, tintColor }) => (
          <TabBarIcon focused={focused} tintColor={tintColor} name="menu" />
        ),
        tabBarLabel: "More",
      },
    }

Tab Bar component -

const TabBarIcon = (props) => {
  return (
    <Icon
      name={props.name}
      size={props.size ? props.size : 16}
      color={props.focused ? props.tintColor : "#222222"}
    />
  );
};

Tab Bar options and Component -

  {
    tabBarOptions: {
      activeTintColor: "#2E98FF",
      inactiveTintColor: "#222222"
    },
    tabBarComponent: props => (
      <TabBar
        activeColors={"#FFFFFF"}
        activeTabBackgrounds={"#2E98FF"}
        {...props}
      />
    ),
  },

Any way to fix this?

Screen reloads on every focus

What is expected

The screen should call componentDidMount only on first focus.

What is current behaviour

Is there any way to prevent screen refresh on tab focus? I have added some api calls on componentDidMount and this is being called on every focus.

Bottom bar overlays content of ScrollView

I started with the expo tab example which is a pretty simple project using a bottom tab bar. I exchanged the bottom tab bar with the animated tab bar component. I noticed that the animated bottom tab bar overlays the content of a ScrollView. In comparison using the default bottom tab bar the ScrollView is above the header so everything can be scrolled into the view.

Do I need to configure something or is this different behavior to the default bar intended? I'm not using the floating variant.

Invariant Violation: Invalid prop `backgroundColor` supplied to `StyleSheet generated`

Invariant Violation: Invalid prop backgroundColor supplied to StyleSheet generated:
Valid color formats are

  • '#f0f' (#rgb)
  • '#f0fc' (#rgba)
  • '#ff00ff' (#rrggbb)
  • '#ff00ff00' (#rrggbbaa)
  • 'rgb(255, 255, 255)'
  • 'rgba(255, 255, 255, 1.0)'
  • 'hsl(360, 100%, 100%)'
  • 'hsla(360, 100%, 100%, 1.0)'
  • 'transparent'
  • 'red'
  • 0xff00ff00 (0xrrggbbaa)

StyleSheet generated: {
"position": "absolute",
"top": 20,
"width": 0,
"height": 0,
"borderRadius": 100,
"backgroundColor": "",
"zIndex": -1
}

<Tabs.Navigator
  tabBarOptions={{
    activeTintColor: "#2F7C6E",
    inactiveTintColor: "#222222",
  }}

>
  <Tabs.Screen name="Home" component={HomeScreen} />
  <Tabs.Screen name="Orders" component={Orders} />
  <Tabs.Screen name="Profile" component={Profile} />
</Tabs.Navigator>

Still rerendering problem.

i'm still facing the issue with the re-rendering problem, there is a configuration or props that im missing?
Every tab change, the active tab re-render, so when i go back, re-render as well

'have your wrapper your NavigationContainer' Bug

'have your wrapper your NavigationContainer' bug still appears to be there even after updating @react-navigation/stack 5.13.0, @react-navigation/native 5.9.0 and @react-navigation/bottom-tabs 5.11.3

Backbutton from navigation back, wrong position in the tabbar

Hi,

woah component ๐Ÿ˜„
Everything is fine in iOS and Android if you use the tabbar navigation (testing with react-navigation v4), but if I use a button that goBack from Tab2 to Tab1 I see this:
image

I am trying to fix it, but if you are faster then me I need some help ๐Ÿ˜ธ

Thx

keyboardHidesTabBar not working

In the tabBarOptions settings on keyboardHidesTabBar, when trying to set "keyboardHidesTabBar": true to hide the tabs when opening the keyboard, even if set to "true", the lib does not hide the tabs and when using the original React Navigation Tabs lib it works. Can someone help me?

TabBar indicator position keeps standing when using navigation.navigate()

Hi, I'm fresher with React Native so if you can give me an advice for my problem it would be more than great.
For example, suppose I've 2 screens called A and B, both of them are inside a TabBar, i can switch between screen A and screen B by clicking on TabBar for normally but in my situation i want to navigate to screen B when i press to a button on screen A. I'm currently using this.props.navigation.navigate('screenB')
and it does switches to screen B but the animation on TabBar doesn't work, it gets stuck at the position of screen A.

Invariant Violation: Invalid prop `backgroundColor` supplied to `StyleSheet generated`:

I created the example and the following error occurs to me:
Invalid prop backgroundColor supplied to StyleSheet generated:
Valid color formats are

  • '#f0f' (#rgb)
  • '#f0fc' (#rgba)
  • '#ff00ff' (#rrggbb)
  • '#ff00ff00' (#rrggbbaa)
  • 'rgb(255, 255, 255)'
  • 'rgba(255, 255, 255, 1.0)'
  • 'hsl(360, 100%, 100%)'
  • 'hsla(360, 100%, 100%, 1.0)'
  • 'transparent'
  • 'red'
  • 0xff00ff00 (0xrrggbbaa)

StyleSheet generated: {
"position": "absolute",
"top": 20,
"width": 0,
"height": 0,
"borderRadius": 100,
"backgroundColor": "",
"zIndex": -1
}

Navbar breaks on changing orientation

I've implemented the bottom nav tab bar for four tabs. It breaks and highlights the wrong part whenever we switch the orientation from portrait to landscape or vice versa. Here are the screenshots:

  1. Navbar fine in portrait mode
    image

    Upon changing orientation to landscape
    image


  1. Navbar fine in landscape mode
    image

    Upon changing orientation to portrait
    image

I really like this navbar and hope to see a resolution for the issue.

how to change the font family of the tab bar?

Hi Torgeadelin,
I'm unable to change the font family of the tab bar can you please add a style prop or add an option to change the font family or guide me on how to change the font family? I will be very thankful to you ๐Ÿ‘

Seems incompatible with ui-kitten eva-icons

I followed the example js to get started, however, an error raised likely related to the Icon rendering:

[Sun Jul 26 2020 23:54:46.387]  ERROR    Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `Icon`.

The official docs written like this:

import React from 'react';
import { Button, Icon } from '@ui-kitten/components';

const FacebookIcon = (props) => (
  <Icon name='facebook' {...props} />
);

export const LoginButton = () => (
  <Button accessoryLeft={FacebookIcon}>Login with Facebook</Button>
);

And I can't see what went wrong.

Please advise.

Tab Animation RTL Support

I'm using "I18nManager" to adding and force RTL (Right To Left) support for Persian language, but the View of the Animation or Active Tab is not support for RTL.

Example:
example-Tab-bar

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

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.

Invalid Hook Call. Hooks can only be called inside body of functional component

Problem
I have made a fresh project to react native and installed this library along with React Navigation 5. I followed all instructions according to the given documentation but I'm getting an error regarding invalid hooks to call in TabBarElement.js.

Expected
The library should work as it is working in the demo video and pictures.

Environment
This is my package.json file
{
"name": "pocketchef",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.13.2",
"@react-native-community/checkbox": "^0.5.6",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-firebase/app": "^10.1.0",
"@react-native-firebase/auth": "^10.1.1",
"@react-native-firebase/database": "^10.1.1",
"@react-native-firebase/storage": "^10.1.1",
"@react-navigation/bottom-tabs": "^5.11.2",
"@react-navigation/drawer": "^5.11.4",
"@react-navigation/material-top-tabs": "^5.3.10",
"@react-navigation/native": "^5.8.10",
"@react-navigation/stack": "^5.12.8",
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-animatable": "^1.3.3",
"react-native-animated-nav-tab-bar": "^3.0.5",
"react-native-gesture-handler": "^1.9.0",
"react-native-image-picker": "^2.3.4",
"react-native-material-dropdown": "github:noway/react-native-material-dropdown",
"react-native-modal": "^11.5.6",
"react-native-paper": "^4.4.1",
"react-native-ratings": "^7.3.0",
"react-native-reanimated": "^1.13.2",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.15.0",
"react-native-share": "^4.1.0",
"react-native-shared-element": "^0.7.0",
"react-native-tab-view": "^2.15.2",
"react-native-vector-icons": "^7.1.0",
"react-native-video": "^5.1.0-alpha8",
"react-native-youtube": "^2.0.1",
"react-navigation-shared-element": "^5.0.0-alpha1",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "7.12.9",
"@babel/runtime": "7.12.5",
"@react-native-community/eslint-config": "1.1.0",
"babel-jest": "25.5.1",
"eslint": "6.8.0",
"jest": "25.5.4",
"metro-react-native-babel-preset": "0.59.0",
"react-test-renderer": "16.13.1"
},
"jest": {
"preset": "react-native"
}
}

Screenshot
Simulator Screen Shot - iPhone 11 - 2020-12-17 at 11 58 36

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.