Is there any way to control the systemback when th...
# compose-android
a
Is there any way to control the systemback when the m3 modalbottomsheet is being shown?
s
What do you mean by “control”?
a
Disable/Enable conditionally.
s
Does BackHandler() not fit your needs here?
a
BackHandler doesn’t work in these cases.
s
Are you hitting this https://issuetracker.google.com/issues/297380343 issue perhaps? If not, what do you mean by “doesn’t work”?
a
I don’t have that flag in the manifest, and the issue is that it is getting dismissed, even If I use BackHandler.
s
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
I did, but I will recheck to confirm.
Yup, both of them get ignored.
s
There's no way to disable that I believe, so whatever custom back logic you need to do, try doing it in
onDismissRequest
.
s
When does onDismissRequest run though? Is it after or before the decision to dismiss is already made?
a
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
Yes, since it is executed post-dismissal, I essentially can’t disable the sheet dismissal.
a
Oh, so you want something like
DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
but for ModalBottomSheet? Wouldn't overriding
confirmValueChange
help with that use-case?
s
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
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.