torgeadelin / react-native-animated-nav-tab-bar

A simple and customisable React Native component that implements an animated bottom tab bar for React Navigation.
MIT License
893 stars 101 forks source link

Possible to hide a specific tab? #74

Closed macist-m closed 2 years ago

macist-m commented 3 years ago

Hello, with regular tab navigation, it is possible to hide a specific tab form the bar with this...

<Tab.Navigator
      screenOptions={({ route }) => ({
        tabBarButton: [
          "Route1ToExclude",
          "Route2ToExclude"
        ].includes(route.name)
          ? () => {
              return null;
            }
          : undefined,
      })}
    >

Yet this is not working with react-native-animated-nav-tab-bar...

İs it possible to hide a tab with stack navigation nested in?

namachan0219 commented 3 years ago

@macist-m I hope you find my hack helpful! Bottom Implement it in the Stack Navigator nested in the Navigator.

// add your stack navigator 
import React, { useLayoutEffect } from "react";
import { getFocusedRouteNameFromRoute } from "@react-navigation/native";

const navName: any = getFocusedRouteNameFromRoute(route);

useLayoutEffect(() => {
switch (navName) {
case "The stack screen name you want to hide.....":
navigation.setOptions({ tabBarVisible: false });
break;

  default:
    navigation.setOptions({ tabBarVisible: true });
    break;
}
return;
}, [navigation, route]);
github-actions[bot] commented 2 years ago

Stale issue message