Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Homitag14 opened this issue Dec 31, 2022 · 7 comments
Open

Comments

@Homitag14
Copy link

No description provided.

@HardMode2015
Copy link

same here ...

@draturi95
Copy link

draturi95 commented Apr 19, 2023

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

@LuamLeite
Copy link

@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
Copy link

draturi95 commented May 1, 2023

@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
Copy link

jelyqs commented May 11, 2023

@LuamLeite

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

Thank you.

@Tvkaes
Copy link

Tvkaes commented May 24, 2023

can someone explain better that example or have one done

@xgenem
Copy link

xgenem commented Nov 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@xgenem @HardMode2015 @LuamLeite @jelyqs @Homitag14 @Tvkaes @draturi95 and others