Thread
#compose
    Halil Ozercan

    Halil Ozercan

    2 years ago
    Hello everyone, is there currently a suggested way of handling navigation in compose? Especially stacked navigation where the bottom view is expected to remain as it is in case user navigates back(kind of like using
    add
    in fragment transactions).
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    andylamax

    andylamax

    2 years ago
    Is compose going to come with an official router? or are we going to rely on external libs?
    Halil Ozercan

    Halil Ozercan

    2 years ago
    I've tried using this library but as I said it doesn't seem to support stacked navigation. Maybe that's even discouraged, idk. I also checked out the sample project which had a back press supporting navigation. However, it also recomposes the pages when user returns back to them. Biggest give away by just using is the fact that it doesn't preserve scroll position for lists.
    @andylamax I strongly believe it will come out with an official router or an official extension to use jetpack navigation. Although I admit the latter is unlikely.
    Zsolt

    Zsolt

    2 years ago
    @Halil Ozercan 1. yes it recomposes (imagine if it wouldn’t), but it also allows you to save / restore state 2. not sure I understood your stacked example right, but if you use nested Routers and not just a flat one for navigation, it shouldn’t be a problem
    Halil Ozercan

    Halil Ozercan

    2 years ago
    From your example, I understood how to save/restore the state which is awesome. Also, using nested routing makes sense for most use cases but imagine:
    Using bottom bar for navigation where there are 3 different screens: Home, Profile, Settings.
    Default start screen is Home. User scrolls down some content, pagination occurs multiple times. State gets kind of large for save/restore in memory.
    User goes to Profile and then Settings.
    Then user presses back two times to go back to Home.
    Now, this doesn't feel like a case where nested routing would work(does it?). Secondly, recomposing the Home page is expensive at this point. It would be better to leave Home page under other pages. How can I achieve this behavior?
    Zsolt

    Zsolt

    2 years ago
    “State gets kind of large for save/restore in memory” - what exactly goes in your state? I guess you can keep it lean by only having descriptive data (position, ids) to use as cues for restoring more expensive data from other sources instead of storing big objects. “It would be better to leave Home page under other pages” - Maybe someone else can chime in to confirm / deny if this is possible with Compose, i.e. to compose composables without rendering them to the ui.
    i

    Ian Lake

    2 years ago
    FWIW, integration of the Navigation component with Compose is already in the works. That includes saving the state of composables on the back stack
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    You can also try this, which doesn’t implement a router but just gives you transition animations and, more importantly, saving state of previous screens on the backstack: https://github.com/zach-klippenstein/compose-backstack (it’s a couple compose versions behind i think)
    m

    Madhava

    2 years ago
    Oh thats awesome, i'm using compose-router and was wondering about transitions! 🙂