react-native-animated-nav-tab-bar

repository·master·Indexed 22 days ago

https://github.com/torgeadelin/react-native-animated-nav-tab-bar

A customizable, 60FPS animated bottom tab bar component for React Native designed for React Navigation v6. It supports floating styles, custom layouts, and granular appearance configurations via the IAppearanceOptions interface, including control over indicator dots, tab button layouts, and element display options.

Tokens
3.1K
Snippets
14
Records
16
Agent score
77%

What's inside react-native-animated-nav-tab-bar

  1. Initialize the AnimatedTabBarNavigator

    master

    To use the component, import AnimatedTabBarNavigator and use it to create a navigator instance. This instance follows the React Navigation pattern, providing a .Navigator component and .Screen components.

    import { AnimatedTabBarNavigator } from "react-native-animated-nav-tab-bar";
    
    const Tabs = AnimatedTabBarNavigator();
    
    export default () => (
      <Tabs.Navigator
        tabBarOptions={{
          activeTintColor: "#2F7C6E",
          inactiveTintColor: "#222222"
        }}
      >
        <Tabs.Screen name="Home" component={Home} />
        {/* Add other screens here */}
      </Tabs.Navigator>
    );
  2. Troubleshoot tab bar styling issues

    master

    Padding issues with tabStyle

    If paddingTop in your tabStyle object is not reflecting correctly, you must also provide the same value for the topPadding property within the appearance prop. This is because the active background/dot uses absolute positioning and is not affected by the parent's padding.

    Appearance prop not applying

    Ensure you are using the correct spelling: appearance. Older versions (pre-3.1.3) had a typo (appearence).

  3. Add icons to the Tab Bar

    master

    You can add icons to your tabs by using the tabBarIcon option on a Tabs.Screen. It is recommended to use react-native-vector-icons for this purpose.

    import Icon from 'react-native-vector-icons/Feather';
    
    // Inside your Tabs.Navigator
    <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}
            />
        )
      }}
    />
  4. Configure the appearance prop

    master

    The appearance prop allows for deep customization of the tab bar's layout, colors, and behavior.

    Note: Reload your view after changing these props, as animations might get stuck during dynamic updates.

    appearance: {
      "topPadding": "Space between the tab button and the wrapper (default: 20)",
      "horizontalPadding": "Vertical space between for the tab buttons (default: 20)",
      "tabBarBackground": "Background color for the wrapper (default: 'white')",
      "shadow": "If true, the wrapper has a light shadow (default: true)",
      "activeTabBackgrounds": "Array of hex colours for the background of each tab when active.",
      "activeColors": "Array of hex colours for the tint of each tab when active.",
      "floating": "If true, the nav bar will float on top of the current screen (default: false)",
      "whenActiveShow": "Appearance of active tab: 'both', 'label-only', or 'icon-only' (default: 'both')",
      "whenInactiveShow": "Appearance of inactive tabs: 'both', 'label-only', or 'icon-only' (default: 'icon-only')",
      "tabButtonLayout": "Layout of the tab button: 'vertical' or 'horizontal' (default: 'horizontal')",
      "dotCornerRadius": "Corner radius for the active background / dot (default: 100)",
      "dotSize": "Size of dot for the active tab: 'small', 'medium', or 'large' (default: 'medium')"
    }
  5. Configure tabBarOptions

    master

    The tabBarOptions prop is passed directly to React Navigation and allows you to control basic styling for the tab items.

    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 (overrides appearance props).",
      "labelStyle": "Style object for the tab label text."
    }
  6. Configure tab bar appearance and layout types

    master

    The library exports several types to control the visual appearance and layout of the tab bar elements:

    • IAppearanceOptions: Configuration object for the visual style of the tab bar.
    • TabButtonLayout: Defines the layout structure of the individual tab buttons.
    • TabElementDisplayOptions: Controls how tab elements are displayed.
    • DotSize: Defines the size of the indicator dots.
    import {
      IAppearanceOptions,
      TabButtonLayout,
      TabElementDisplayOptions,
      DotSize
    } from 'react-native-animated-nav-tab-bar';