hoaphantn7604 / react-native-curved-bottom-bar

A high performance, beautiful and fully customizable curved bottom navigation bar for React Native.
MIT License
485 stars 100 forks source link

How to hide bottom tab on some screens nested inside stack navigator #50

Open Homitag14 opened 1 year ago

HardMode2015 commented 1 year ago

same here ...

draturi95 commented 1 year ago

This can be done as below:

  1. Create a tabBarRef for your bottom navigator:
export const tabBarRef = createRef() 
  1. Add it to your bottom navigator:

    
    <CurvedBottomBar.Navigator
      ref={tabBarRef}
      ...
    >
    ...
    </CurvedBottomBar.Navigator>
  2. In your stack navigator that is nested inside the bottom navigator, import the tabBarRef and add a useFocusEffect that hides the bottom navigator when you are on a route that needs the bottom tab to be hidden. Note that since the stack navigator is nested inside the bottom navigator, you get navigation, route objects as props in the stack navigator.

import { tabBarRef } from 'path-to-bottom-navigator'
import {
  getFocusedRouteNameFromRoute,
  useFocusEffect,
} from '@react-navigation/native'
  useFocusEffect(() => {
    const routeName = getFocusedRouteNameFromRoute(route)
    if (
      [
       'route-with-bottom-tab-hidden-1', 
       'route-with-bottom-tab-hidden-2', 
        ...
      ].includes(routeName)
    ) {
      tabBarRef.current.setVisible(false)
    } else {
      tabBarRef.current.setVisible(true)
    }
  })
LuamLeite commented 1 year ago

@draturi95 where should I get the route variable from? I did that useFocusEffect inside the definition of the stackNavigator, but couldn't find the route variable.

draturi95 commented 1 year ago

@LuamLeite

As edited above, Since the stack navigator is nested inside the bottom navigator, you get navigation, route objects as props in the stack navigator.

jelyqs commented 1 year ago

@LuamLeite

Hi you, can you share the bottom menu code to handle this problem?

Thank you.

Tvkaes commented 1 year ago

can someone explain better that example or have one done

xgenem commented 1 year ago

Why do you have to do this when you can have them on the same hierarchy as this tab navigator?