How can I avoid ModalBottomSheet from full expanding when using `sheetState.show()`? I would like to...
r
How can I avoid ModalBottomSheet from full expanding when using
sheetState.show()
? I would like to get it half expanded when user opens it. I tried to use
scope.launch { sheetState.animateTo(ModalBottomSheetValue.HalfExpanded) }
, but then app is crashing.
1
j
Not sure if it’s the best solution, but we accomplished this by making the content of our bottom sheet less than 50% of the screen height. Based on the
sheetState.show()
docs when the content is smaller than 50% of the screen height the sheet will be shown at half height, otherwise it’s full.
hmm, this is ModalBottomSheetState to be specific. Not sure which bottom sheet you’re using
Make sure the initialValue of your state is set to HalfExpanded as well
r
I’m also using
ModalBottomSheetState
, so much of states in the code that Mutable came in mind while writing 😄 But thanks for the info, I assume that there is some kind of logic of when it’s possible to show all data with fully expanded then it’s fully showing up, because I have same bottom sheet implementation in other place in the app and it’s half expanded on opening, but it contains way more data that can’t be fully displayed.
j
gotcha. I’d expect animateTo to work as well. What exception does it throw when you try that?
r
Don’t remember, but at the moment it randomly started to work. 🫠 Spent so much time on this…😄 Probably cache clearing a moment ago helped, otherwise really confusing.
j
yeah, anecdotally we’ve had a hard time with ModalBottomSheet as well like we ran into an issue having nested ModalBottomSheetLayouts so we had to make one global one and then send everything to it which complicates things
c
I think there are new apis in sheetState as of 1.4.0. I think there's like .show() .expand() .openHalfWay() or something
j
There is only
show()
from 1.4.0-alpha04. Show animates to HalfExpanded if that anchor exists. Modal bottom sheets have a HalfExpanded anchor at 50% of the container height if the sheet content is taller than 50% of the container height. I believe the crash you're seeing comes from trying to animate to HalfExpanded when you don't have an anchor for it. Make sure your content is tall enough - but if it isn't tall enough in the first place, you shouldn't need a HalfExpanded state anyway.
1502 Views