Quick question as a sanity check: Is it true that ...
# compose
f
Quick question as a sanity check: Is it true that when using View(XML)-based navigation components, the multi-backstack navigation and state saving is enabled by default but when implementing navigation via compose, we need to specify it ourselves like in this example.
And by "enabled by default" I mean provided by
bottomNav.setupWithNavController(controller)
. Compose navigation does not have such "connector" provided by the nav library.
i
Correct
f
And why is it the dafault in View-based navigation when material spec says that the state shouldn't be saved? 🤔
On Android, revisiting a section resets the app, returning the user to its top-level screen.
And is it just omission of such "connector" in Compose navigation or is it not meant to be the default behavior? Sorry for possibly dumb questions. I am just a little confused 😅 I started debugging old app and the nav behavior was different than I am used to from the Compose world
i
The material docs are out of date and haven't yet been updated (they were true when it wasn't possible to save state. Now it is possible)
Compose doesn't impose using Material components or Material3 components: you can use any set of components you want. A connector made a lot less sense than just pointing out the three lines you can use with any bottom nav / drawer implementation you want
f
Fair enough, thank you Ian 👍
One sort of follow-up question: Let's say I have a bottom nav with items
A
and
B
and another screen
C
which is opened from
A
. I start on screen
A
(as a start destination), navigate to
C
and then switch to
B
using bottom navigation. Now I am at
B
but
C
should be saved in a "separate back stack" meaning that
C
should be displayed when I navigate to A, correct? So now when I 1. navigate from
B
to
A
using bottom nav the
C
is displayed 2. navigate from
B
to
A
using the system back button, the
A
is displayed Not sure if this is correct or not. 3. navigate from
B
to
A
using the system back button (I am at
A
), navigate back to
B
using bottom nav (I am at
B
) and navigate to
A
using bottom nav, I would expect to land on
A
because I just was at
A
and the state was not restored but I end up back on
C
- the back stack was restored. Is this expected behavior? Because it does not feel right. I would either expect to
A->C
saved back stack be removed when I pop up to start destination or restored same way as with navigating.
😶 and not Compose, I know but I couldn't find anyone else with this question so I though I'll ask here.