theapache64

    theapache64

    1 year ago
    🧭 Navigation : Nested navigation with
    bottomSheet
    🧵
    What’s the correct way to implement nested navigation inside
    bottomSheet
    (Material Navigation)? Can i use the
    navigation
    method?
    ModalBottomSheetLayout{
        NavHost{
            composable("home"){}
            bottomSheet("detail"){
                navigation { ⬅️
                    composable("a") {}
                    composable("b") {}
                    composable("c") {}
                }
            }
            composable("about"){}
        }
    }
    or should I use nested
    NavHost
    ?
    ModalBottomSheetLayout{
        NavHost{
            composable("home"){}
            bottomSheet("detail"){
                NavHost { ⬅️
                    composable("a") {}
                    composable("b") {}
                    composable("c") {}
                }
            }
            composable("about"){}
        }
    }
    🤔
    cc @Ian Lake
    i

    Ian Lake

    1 year ago
    The first doesn't do anything at all - you're calling a DSL builder method inside a random Composable
    theapache64

    theapache64

    1 year ago
    Okay, i haven’t tried both. what abt the second one ?
    i

    Ian Lake

    1 year ago
    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)
    theapache64

    theapache64

    1 year ago
    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

    Ian Lake

    1 year ago
    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
    theapache64

    theapache64

    1 year ago
    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

    Ian Lake

    1 year ago
    I mean, you can use a
    dialog
    destination if you want it to be displayed above other floating windows and regular destinations
    theapache64

    theapache64

    1 year ago
    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

    Ian Lake

    1 year ago
    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
    theapache64

    theapache64

    1 year ago
    Wow 😮 I didn’t know about
    dialog
    destination. Didn’t see this in documentation either. Is this new?
    i

    Ian Lake

    1 year ago
    theapache64

    theapache64

    1 year ago
    alright 👍 that should fix my problem. thank you so much 🤝
    Colton Idle

    Colton Idle

    1 year ago
    @theapache64 curious if you figured out your issue. Let me know!
    theapache64

    theapache64

    1 year ago
    @Colton Idle nope. i thought
    dialog
    would fix, but
    dialogs
    are also not back-navigate-able from a regular destination
    Colton Idle

    Colton Idle

    1 year ago
    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.
    theapache64

    theapache64

    1 year ago
    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 navigate to the previous screen to navigate back the dialog.
    Colton Idle

    Colton Idle

    1 year ago
    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.
    theapache64

    theapache64

    1 year ago
    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 😄
    Colton Idle

    Colton Idle

    1 year ago
    Yep. I'd try another nav library
    or create your own modal composable
    theapache64

    theapache64

    1 year ago
    Yeah, I’ve decided to move with custom nav lib.