6.0.0 • Published 5 months ago

@adrok-group/react-navigation-bottom-tabs v6.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Custom React Navigation Bottom Tabs

Reanimated v3 version React Navigation v6 npm npm runs with expo

This extension to @react-navigation/bottom-tabs introduces a seamless solution for managing a large number of tabs. When the tabs exceed a specified limit, the last tab automatically transforms into a 'More' tab, revealing a Bottom Sheet with the remaining tabs.

Inspired by:

Screenshots

Installation

yarn add @adrok-group/react-navigation-bottom-tabs

Usage

import { createBottomTabNavigator } from '@adrok-group/react-navigation-bottom-tabs';

const Tab = createBottomTabNavigator();

const MyTabs = () => {
  return (
    <Tab.Navigator
      initialRouteName="List"
      screenOptions={{
        tabBarMaxVisibleTabs: 5, // add this line
      }}
    >
      <Tab.Screen name="List" component={ListScreen} />
      <Tab.Screen name="Recipe" component={RecipeScreen} />
      <Tab.Screen name="Pantry" component={PantryScreen} />
      <Tab.Screen name="MealPlan" component={MealPlanScreen} />
      <Tab.Screen name="Profile" component={ProfileScreen} />
      <Tab.Screen name="Settings" component={SettingsScreen} />
    </Tab.Navigator>
  );
};

Properties

PropertyDescriptionTypeDefault Value
... (the original properties)... (directly related to @react-navigation/bottom-tabs)--
tabBarMaxVisibleTabsMax visible tabs including "More" tab.number4
tabBarPulseOnPressEnable pulse animation on tab press.booleantrue
tabBarIconSizeSize of the tab bar icons.number28
tabBarMoreAccessibilityLabelAccessibility label for the "More" tab.string-
tabBarMoreTestIDTestID for the "More" tab.string-
tabBarMoreShowLabelShow label for the "More" tab.booleantabBarShowLabel | true
tabBarMoreAllowFontScalingAllow font scaling for the "More" tab label.booleantabBarAllowFontScaling | -
tabBarMoreActiveTintColorActive tint color for the "More" tab.stringtabBarActiveTintColor | Primary color from theme
tabBarMoreInactiveTintColorInactive tint color for the "More" tab.stringtabBarInactiveTintColor | Text color from theme
tabBarMoreActiveBackgroundColorActive background color for the "More" tab.stringtabBarActiveBackgroundColor | 'transparent'
tabBarMoreInactiveBackgroundColorInactive background color for the "More" tab.stringtabBarInactiveBackgroundColor | 'transparent'
tabBarMoreButtonCustom component for the "More" tab button.(props: BottomTabBarButtonProps) => ReactNode-
tabBarMoreItemStyleStyle for the "More" tab item.styletabBarItemStyle | -
tabBarMoreIconCustom icon for the "More" tab.(props: BottomTabBarIconProps) => ReactNode-
tabBarMoreIconStyleStyle for the "More" tab icon.styletabBarIconStyle | -
tabBarMoreIconSizeSize of the "More" tab icon.numbertabBarIconSize | 28
tabBarMoreLabelCustom label for the "More" tab.string'More'
tabBarMoreLabelStyleStyle for the "More" tab label.styletabBarLabelStyle | -
tabBarMoreBadgeBadge for the "More" tab.(props: BottomTabBarBadgeProps) => ReactNode-
tabBarMoreBadgeStyleStyle for the badge on the "More" tab.styletabBarBadgeStyle | -
tabBarMoreBottomSheetBackdropStyleStyle for the backdrop of the Bottom Sheet in "More" tab.style-
tabBarMoreBottomSheetModalStyleStyle for the modal of the Bottom Sheet in "More" tab.style-
tabBarMoreBottomSheetActiveTintColorActive tint color for Bottom Sheet items in "More" tab.stringtabBarActiveTintColor | Primary color from theme
tabBarMoreBottomSheetInactiveTintColorInactive tint color for Bottom Sheet items in "More" tab.stringtabBarInactiveTintColor | Text color from theme
tabBarMoreBottomSheetActiveBackgroundColorActive background color for Bottom Sheet items in "More" tab.stringtabBarActiveBackgroundColor | 'transparent'
tabBarMoreBottomSheetInactiveBackgroundColorInactive background color for Bottom Sheet items in "More" tab.stringtabBarInactiveBackgroundColor | 'transparent'
tabBarMoreBottomSheetButtonCustom component for Bottom Sheet items in "More" tab.(props: BottomTabBarButtonProps) => ReactNode-
tabBarMoreBottomSheetItemStyleStyle for Bottom Sheet items in "More" tab.styletabBarItemStyle | -
tabBarMoreBottomSheetIconCustom icon for Bottom Sheet item in "More" tab.(props: BottomTabBarIconProps) => ReactNode-
tabBarMoreBottomSheetIconStyleStyle for Bottom Sheet icons in "More" tab.styletabBarIconStyle | -
tabBarMoreBottomSheetIconSizeSize of Bottom Sheet icons in "More" tab.numbertabBarIconSize | 28
tabBarMoreBottomSheetLabelCustom label for Bottom Sheet item in "More" tab.stringtabBarLabel | -
tabBarMoreBottomSheetLabelStyleStyle for Bottom Sheet labels in "More" tab.styletabBarLabelStyle | -
tabBarMoreBottomSheetBadgeStyleStyle for badges on Bottom Sheet items in "More" tab.styletabBarBadgeStyle | -

Not supported original properties from @react-navigation/bottom-tabs

PropertySupported
tabBarHideOnKeyboard❌ (Not applicable)
tabBarVisibilityAnimationConfig❌ (Not applicable)

Full Example

import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import {
  NavigationContainer,
  type CompositeScreenProps,
  type NavigatorScreenParams,
} from '@react-navigation/native';
import {
  createNativeStackNavigator,
  type NativeStackScreenProps,
} from '@react-navigation/native-stack';
import { createBottomTabNavigator, type BottomTabScreenProps } from '../../src';

/* Your Param List */

type MyTabsParamList = {
  List: undefined;
  Recipe: undefined;
  Pantry: undefined;
  MealPlan: undefined;
  Profile: undefined;
  Settings: undefined;
};

type RootStackParamList = {
  MyTabs: NavigatorScreenParams<MyTabsParamList>;
};

export type RootStackScreenProps<R extends keyof RootStackParamList> =
  NativeStackScreenProps<RootStackParamList, R>;

/* MyTabs is a nested navigator within the RootStack navigator */

export type MyTabsScreenProps<R extends keyof MyTabsParamList> =
  CompositeScreenProps<
    BottomTabScreenProps<MyTabsParamList, R>,
    NativeStackScreenProps<RootStackParamList>
  >;

/* Your Screens */

const ListScreen = (props: MyTabsScreenProps<'List'>) => {
  return <View />;
};

const RecipeScreen = (props: MyTabsScreenProps<'Recipe'>) => {
  return <View />;
};

const PantryScreen = (props: MyTabsScreenProps<'Pantry'>) => {
  return <View />;
};

const MealPlanScreen = (props: MyTabsScreenProps<'MealPlan'>) => {
  return <View />;
};

const ProfileScreen = (props: MyTabsScreenProps<'Profile'>) => {
  return <View />;
};

const SettingsScreen = (props: MyTabsScreenProps<'Settings'>) => {
  return <View />;
};

const Tab = createBottomTabNavigator<MyTabsParamList>();

const MyTabs = () => {
  return (
    <Tab.Navigator
      initialRouteName="List"
      screenOptions={{
        tabBarMaxVisibleTabs: 5,
      }}
    >
      <Tab.Screen name="List" component={ListScreen} />
      <Tab.Screen name="Recipe" component={RecipeScreen} />
      <Tab.Screen name="Pantry" component={PantryScreen} />
      <Tab.Screen name="MealPlan" component={MealPlanScreen} />
      <Tab.Screen name="Profile" component={ProfileScreen} />
      <Tab.Screen name="Settings" component={SettingsScreen} />
    </Tab.Navigator>
  );
};

const RootStack = createNativeStackNavigator<RootStackParamList>();

export default function App() {
  return (
    <View style={styles.container}>
      <NavigationContainer>
        <RootStack.Navigator>
          <RootStack.Screen
            name="MyTabs"
            component={MyTabs}
            options={{ headerShown: false }}
          />
        </RootStack.Navigator>
      </NavigationContainer>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library