# compose

Zoltan Demant

03/04/2024, 11:10 AM
Im trying to understand what happens to my
when using it with
. Details in 🧵
My root composable renders a List<Screen>, using AnimatedContent to show the top-most entry, and SaveableStateHolder to keep screen states around while theyre in the backstack. One of my screens conditionally shows a ModalBottomSheet, and I think the issue is that after dismissing it at least once, further calls to rememberModalBottomSheet will return an instance with restored values. Specifically, SheetValue will be EXPANDED instead of HIDDEN to begin with, and thus the sheet will just jump to it, instead of animating between the two. I can verify that sheetState.hide() always completes, so my thinking here is that its state might simply be saved BEFORE sheetState.hide() completes, due to the ModalBottomSheet being removed from the composition a bit too early? Im dismissing it using something akin to launch { state.hide() }.invokeOnCompletion { currentOnDismiss() }; but Im at the same time also navigating to another screen. I can think of two workarounds: - Use key(x) around the sheet, so everytime the sheet shows up, it will be a unique sheet with its own state. This ruins its rememberSaveable though. - Render the ModalBottomSheet outside of the SaveableStateHolder content. This seems like the golden ticket, just requires some additional work. Is my thinking correct? Can you see some other workaround?