:compass: Navigation : Nested navigation with `bot...
# compose
t
🧭 Navigation : Nested navigation with
bottomSheet
🧵
What’s the correct way to implement nested navigation inside
bottomSheet
(Material Navigation)? Can i use the
navigation
method?
Copy code
ModalBottomSheetLayout{
    NavHost{
        composable("home"){}
        bottomSheet("detail"){
            navigation { ā¬…ļø
                composable("a") {}
                composable("b") {}
                composable("c") {}
            }
        }
        composable("about"){}
    }
}
or should I use nested
NavHost
?
Copy code
ModalBottomSheetLayout{
    NavHost{
        composable("home"){}
        bottomSheet("detail"){
            NavHost { ā¬…ļø
                composable("a") {}
                composable("b") {}
                composable("c") {}
            }
        }
        composable("about"){}
    }
}
šŸ¤”
cc @Ian Lake
i
The first doesn't do anything at all - you're calling a DSL builder method inside a random Composable
t
Okay, i haven’t tried both. what abt the second one ?
i
The second one seems like exactly the case where a nested NavHost would make sense (when the containing bounds of the NavHost are completely different)
t
Cool.
I’ve another follow up question. Suppose I am going from
c
to
about
, and when I press back from
about
, I need to go back to
c
, What’s the best way to do that? Also note that, I can also go to
about
from
home
. Basically,
about
should be accessible from anywhere. so what would be the best approach to do this?
i
This is the same conversation we've already had, isn't it? You can't put a
FloatingWindow
destination like your bottom sheet on the back stack
t
This is the same conversation we’ve already had, isn’t it?
Yes 😬
You can’t put aĀ 
FloatingWindow
Ā destination like your bottom sheet on the back stack
Is there anyyyyy way I can make a regular destination transparent? I know its not available right now, but would it be possible if I raise a feature request? OR it’s completely impossible with respect to navigation lib’s current architecture and i shouldn’t expect that feature in future versions? 😐
i
I mean, you can use a
dialog
destination if you want it to be displayed above other floating windows and regular destinations
t
but as soon as i navigate to a regular destination, the
dialog
will be removed, right? means, when i nav back it won’t go to the
dialog
but the previous regular destination. isn’t it ? šŸ¤”
as per my design, destination should have the ability to become transparent as well as back-navigateable.
i
I'm saying that
about
could be a
dialog
destination, then you could navigate to it from your bottom sheet and go back to your bottom sheet when it closes
t
Wow 😮 I didn’t know about
dialog
destination. Didn’t see this in documentation either. Is this new?
i
t
alright šŸ‘ that should fix my problem. thank you so much šŸ¤
c
@theapache64 curious if you figured out your issue. Let me know!
t
@Colton Idle nope. i thought
dialog
would fix, but
dialogs
are also not back-navigate-able from a regular destination
c
I wonder if you can just fake it. i.e. Box{ YourContent() FakeModal() } FakeModal is fullscreen, but it's just a transparent black background with a card in the middle. Effectively just faking it.
t
My navigation graph is very dynamic and complex. Moving with a hack would be only a temporary solution. As the complexity increases, backstack management will become a pain in the ass. The suggested solution would work for small/medium apps. In fact, the same behaviour can be achieved with a combination of
dialog
destination and
saveState/restoreState
flags. The problem is, we’ll need to na*vigate to the previous screen to navigate back the dialog*.
c
Yeah. I mean I don't think dialogs ever stay on the back stack even in fragment based nav.
https://developer.android.com/guide/navigation/navigation-navigate#back-stack "My navigation graph is very dynamic and complex." I can't really relate to that so maybe I'm not seeing something that you are. In general though... navigation never supported floating windows in the backstack which is the main reason why I asked
"@theapache64Ā curious if you figured out your issue. Let me know!"
I was curious if you knew something I didn't know about it. lol. If anything... I think there are a few other libs for navigation. Zach Klippenstein (he/him) [MOD] has one I believe, and decompose is another mpp nav lib I think too.
t
Yeah. the above given illustration is correct. My problem is i want to nav back to
dialog
from regular destination which is impossible at the moment šŸ˜„
c
Yep. I'd try another nav library
or create your own modal composable
t
Yeah, I’ve decided to move with custom nav lib.