0

I have some items in a modal sheet layout and when I press an Item, I navigate to another screen. However, when I press back button in the detail screen, the modal sheet reappears with a flashing behavior. I think this is because of recomposition but is there a way to prevent the recomposition without using a box and hiding-revealing the other screen? Any help is appreciated.

Subfly
  • 492
  • 2
  • 13
  • "I think this is because of recomposition" - re-composition happens a lot so its hard to guess, can you provide some reproducible code?, something that can be copy and pasted for us to see the problem. – z.g.y Oct 24 '22 at 11:51

2 Answers2

0

Maybe you need to pop the bottom sheet from the backstack?

When navigating to your detail screen from the bottom sheet, get the instance of the BottomSheetNavigator you used to create the ModalBottomSheetLayout and do:

bottomSheetNavigator.popBackStack(backstackEntry, true)

You get the backstackEntry from the lambda when calling bottomSheet(route)

Martyna Maron
  • 371
  • 4
  • 19
  • Thank you for your answer but I solved the problem by adding the necessary screens to another navgraph and opening it inside the modal sheet. However, what I wanted was making the modal sheet stay in expanded state when I navigate to another screen but as the previous screen re-composes on navigating back, the modal sheet were also opening itself again from hidden to expanded state. However, I still wonder if there are any solutions to prevent the recomposition of the model sheet or the previous screen in compose. – Subfly Oct 25 '22 at 11:20
0

@Subfly Can you provide the solution you have implemented for this issue, I'm facing similar issue at my end, also raised a question ModalBottomSheetLayout flashes on back navigation (Jetpack Compose)