adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.51k stars 126 forks source link

How to hide bottom tab bar at specific screens? #259

Open chihirooooooooo opened 9 months ago

chihirooooooooo commented 9 months ago

I have bottom tab bar at an app, but I want to hide it at specific screes. How to implement that?

ArleyPereira commented 3 months ago

Has anyone found any solution for this case?

Egi10 commented 4 weeks ago

You can use Nested Navigator, as mentioned in this issue: https://github.com/adrielcafe/voyager/issues/204.

To get the root, I implemented it like this:

fun findRootNavigator(
    currentNavigator: Navigator,
    depth: Int
): Navigator {
    return if (depth == 0 || currentNavigator.parent == null) {
        currentNavigator
    } else {
        return findRootNavigator(
            currentNavigator = currentNavigator.parent!!,
            depth = depth - 1
        )
    }
}
val currentNavigator = LocalNavigator.currentOrThrow
        val targetNavigator = findRootNavigator(
            currentNavigator = currentNavigator,
            depth = 2
        )
targetNavigator.push(
                            item = DetailsScreen()
                        )