https://kotlinlang.org logo
#compose
Title
# compose
z

Zoltan Demant

09/22/2023, 6:16 AM
Anyone else having issues with M3
ModalBottomSheet
sticking around a lil too long after being dismissed, and interactions being ignored in the in meantime?
Apparently its been reported already! Please star the issue 🙂
a

ascii

09/22/2023, 6:30 AM
I see that issue notes M3 version as 1.1.0 (stable). Have you tried any of the alpha releases yet?
z

Zoltan Demant

09/22/2023, 7:55 AM
Yup, Im on 1.2.0-alpha08, I should state this in the comment I made on the issue as well!
a

ascii

09/22/2023, 8:55 AM
Did some quick testing. It seems to be a side-effect of how & when
onDismissRequest
is called. This lambda would usually have your sheet hiding logic, e.g. setting a state variable to
false
. Tapping on the scrim immediately calls it (only if scrim color
isSpecified
); thus content "behind" the sheet can also be interacted with immediately, because sheet is removed from the composition. Dismissing by pressing back or swiping down plays out an animation first, and then calls
onDismissRequest
via
invokeOnCompletion
. Coroutines & iOC may have their own overhead that brings out delays. However, I wouldn't say it lasts for 2s; that's way too long. In my case it's a few hundred milliseconds. See for yourself: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]kotlin/androidx/compose/material3/ModalBottomSheet.android.kt
The way it's set up right now is that the bottom sheet window consumes all touch events (?), so it has to be removed from comp
z

Zoltan Demant

09/22/2023, 9:07 AM
Thanks for digging into it! 😃
The way it's set up right now is that the bottom sheet window consumes all touch events (?), so it has to be removed from comp
This sounds like the underlying issue. Agreed about it not being 2s, however seems to be long enough that my first touch event after dismissing it is ignored almost everytime.
Tapping on the scrim immediately calls it (only if scrim color
isSpecified
); thus content "behind" the sheet can also be interacted with immediately, because sheet is removed from the composition.
If I understand you correctly, in this case the sheet will simply disappear without any animation?
a

ascii

09/22/2023, 9:14 AM
Actually, no. Ignore what I said about scrims doing it immediately. It still animates and behaves the same as back/swipe. I assumed wrong because the function name ``onDismissRequest`` is same across ModalBottomSheet and Scrim, which is a separate composable.
Scrim's
onDismissRequest
is set to
animateToDismiss
, and that function does the animate + invokeOnCompletion thing
z

Zoltan Demant

09/22/2023, 9:27 AM
Ah, gotcha. I do wonder if a workaround/fix is as simple as tweaking the scrim
pointerInput
block, basically removing it when the sheet is dismissing or very close to fully hidden?