https://kotlinlang.org logo
#compose-android
Title
# compose-android
a

Aman Verma

09/21/2023, 12:19 PM
Is there any way to control the systemback when the m3 modalbottomsheet is being shown?
s

Stylianos Gakis

09/21/2023, 12:26 PM
What do you mean by “control”?
a

Aman Verma

09/21/2023, 12:27 PM
Disable/Enable conditionally.
s

Stylianos Gakis

09/21/2023, 12:27 PM
Does BackHandler() not fit your needs here?
a

Aman Verma

09/21/2023, 12:28 PM
BackHandler doesn’t work in these cases.
s

Stylianos Gakis

09/21/2023, 12:28 PM
Are you hitting this https://issuetracker.google.com/issues/297380343 issue perhaps? If not, what do you mean by “doesn’t work”?
a

Aman Verma

09/21/2023, 12:29 PM
I don’t have that flag in the manifest, and the issue is that it is getting dismissed, even If I use BackHandler.
s

Stylianos Gakis

09/21/2023, 12:30 PM
Right, and did you try putting BackHandler both inside the m3.sheet content lambda and outside of it? Do both of them get ignored?
a

Aman Verma

09/21/2023, 12:31 PM
I did, but I will recheck to confirm.
Yup, both of them get ignored.
s

Stylianos Gakis

09/21/2023, 12:34 PM
There's no way to disable that I believe, so whatever custom back logic you need to do, try doing it in
onDismissRequest
.
s

Stylianos Gakis

09/21/2023, 2:39 PM
When does onDismissRequest run though? Is it after or before the decision to dismiss is already made?
a

ascii

09/21/2023, 2:42 PM
I've seen
invokeOnCompletion
being used, so after the dismiss animation completes
Just search for
onDismissRequest()
in that link; there are only 5 matches
a

Aman Verma

09/21/2023, 2:43 PM
Yes, since it is executed post-dismissal, I essentially can’t disable the sheet dismissal.
a

ascii

09/21/2023, 2:44 PM
Oh, so you want something like
DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
but for ModalBottomSheet? Wouldn't overriding
confirmValueChange
help with that use-case?
s

Stylianos Gakis

09/21/2023, 2:44 PM
M3 bottom sheets really are something else to work with. I’ve never filed more bug reports for any other individual component. Maybe if you’re just starting out with it you can consider looking into using the non-experimental M2 bottom sheets instead? Unless those are also problematic to use, I didn’t try them out too much.
a

ascii

09/21/2023, 2:48 PM
I found M2 sheets to be very annoying to work with, because (if I remember correctly) you need to wrap them in a separate *Layout, and handle everything yourself. The only thing I don't like about M3 modal sheets is that it opens itself up even if you supply an initial state of Hidden. Very counter-intuitive, forcing you to use state variables to control it.
10 Views