:compass: <Accompanist’s >`bottomSheet` ’s navEntr...
# compose
t
🧭 Accompanist’s `bottomSheet` ’s navEntry not maintained ( Details inside 🧵)
c
@jossiwolf
t
Scenario: I’ve three screens
A
,
B
and
C
.
A
and
C
are navigation-compose’s
composable
B is Accompanist’s `bottomSheet` When
navigate
from
A
->
B
->
C
and then press back button from
C
, the app goes to
A
rather than
B
Is there anyway to keep the bottomSheet’s state so that when back button pressed it’ll go to
B
?
j
Afaik, there's no way to do that. Bottom Sheets are floating window destinations, same as dialogs. That means that they're automatically popped off the back stack when you navigate to a new destination. cc @Jeremy Woods about customizing that behavior 🙂
t
Okay. @Jeremy Woods is it possible to do? If yes, i can raise a feature request?
n
Could you maybe just relaunch B when you get back to A based on some state value you’d have to keep track of ?
j
No, it's not possible. Me and Ian discussed it for a while and there is no good way for navigation to manage dialogs within the back stack. You can stack FloatingWindows on top of each other, but once you add a regular destination, we pop them all. Here was the explanation pre-Compose https://issuetracker.google.com/134089818#comment7 and I don't think any of those factors have changed.
t
@Nathan that might work. @Jeremy Woods okay, so what’s the recommended approach to achieve this behaviour? what are your thoughts abt @Nathan’s solution?
j
It makes sense. The one thing I would note is that the state of the dialog won't be saved.
t
I can use a viewmodel for that. That would work, right?
j
Now that I think about it, you might even be able to use the
popUpToSavedState
and
restoreSavedState
APIs we added for multiple back stacks. https://developer.android.com/guide/navigation/navigation-navigate#savestate
t
Ohh okay. I thought it wouldn't work with this. I'll give it a try
j
I haven't tried it, but in theory we should be able to save and restore the back stack entry associated with the dialog.
t
Ookay
Note: the code can be improved. consider this as a draft version.