react-native-curved-bottom-bar icon indicating copy to clipboard operation
react-native-curved-bottom-bar copied to clipboard

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

Open Homitag14 opened this issue 2 years ago • 7 comments

Homitag14 avatar Dec 31 '22 15:12 Homitag14

same here ...

HardMode2015 avatar Jan 16 '23 23:01 HardMode2015

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>
  1. 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)
  }
})

draturi95 avatar Apr 19 '23 08:04 draturi95

@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.

LuamLeite avatar May 01 '23 04:05 LuamLeite

@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.

draturi95 avatar May 01 '23 12:05 draturi95

@LuamLeite

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

Thank you.

jelyqs avatar May 11 '23 14:05 jelyqs

can someone explain better that example or have one done

Tvkaes avatar May 24 '23 21:05 Tvkaes

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

xgenem avatar Nov 24 '23 20:11 xgenem