For material3 modal bottom sheet, does anyone feel...
# compose
c
For material3 modal bottom sheet, does anyone feel like they have a good grasp on showing vs hiding the dialog. This snippet here for example confuses me: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mples/BottomSheetSamples.kt;l=104-120?q=bottomSheetSamples.kt
Copy code
scope
 .launch { bottomSheetState.hide() }
 .invokeOnCompletion {
   if (!bottomSheetState.isVisible) {
     openBottomSheet = false
   }
 }
why do you need that invokeOnCompletion, if a few lines above you have
onDismissRequest = { openBottomSheet = false }
a
onDismissRequest
is what
ModalBottomSheet
calls after hiding the sheet with animation. If you just update the state without calling
bottomSheetState.hide()
, the sheet will be immediately dismissed without animation. That’s why you need the snippet if you want to hide the sheet yourself with animation.
c
got it. but why is invokeOnCompleteion needed though?
if it's just flipping my openBottomSheet state to false... isn't that taken care of by onDismissRequest?
a
onDismissRequest
is only called when the sheet is dismissed by gesture or back key.
c
ohhh. okay. so when you call hide() itself... it doesn't call onDismissRequest.
very interesting!
yes black 1
i think i found the culprit in my code. (i was trying to prevent a bototm sheet from being dismissable). and thought i was misunderstanding something, leading to this question. but looks like i found a bug, because if i remove my scollable content in the m3 bottom sheet then everything works fine. but if i have a scrollable item in my m3 bs then all hell breaks loose. ill have to file this one later today.
t
There's issues with nestedscroll and userscroll that where only very recently fixed. Very last version have issues with edgetoedge and status bar too.
y
also when .expand is called it doesn't expand all the way, even tho skip half is step on true
c
dang. why must my design team love bottom sheets lol
t
:) And to duplicate and edit yourself you need to copy 5 files at least as all is private / internal.
😭 3
🙂 2
c
Found another issue in my code similar to this. Does anyone know if using modalSheetState.show() is wrong? seems like i want to keep my own state to use for the if statement?
y
yap similar here i used to do that now its just I create my own state
c
@jossiwolf can you chime in here pretty please 😅
j
What is the issue?
c
So my team is basically using if (bottomSheetState.isVisible){ BottomSheet } like... everywhere. and it seems to work. but this sample says otherwise. Also. Now that I have modalSheetState I can call show() on it. which makes sense. but it sounds like you want me to create an additional source of truth. like
if (openBottomSheet) {
but... yeah. then i feel like i have two states to represent the same thing.
Like. should my team ban the use of modalSheetState.show()? it only seems to get us in trouble.
j
The conditional just allows you to include/exclude the sheet from the hierarchy. The sheet state represents the visibility. You can always keep the sheet around (while hiding the sheet), but the recommended way is to synchronize these. What issues are you facing with
show
?
c
We were doing
if (sheetState.isVisible)
and after you dismissed the sheet (by clicking outside the sheet) then it would dismiss. but you cant bring it up again.
j
That sounds like a bug then, have you filed one? Overall feedback about asymmetry in the API shape taken though
c
Interesting. Yeah. Its dead simple simple. We're basically just using sheetState.show() and if (sheetState.isVisible) and the sheet works fine the first time. but after its dismissed via sheetState.hide() it dies. I've tried on latest stable. I will try to submit a bug if anything, but it'll take me a while as I moved onto another project now that that bug is fixed. #contractorlife
👍 1