Utkarsh Tiwari
01/26/2021, 3:31 AMModalBottomSheetLayout
, however, when I state.show()
the modal, it expands to only cover half the screen height. I have to swipe-up to pull it to make it expand to cover the entire screen. What did I miss?Utkarsh Tiwari
01/26/2021, 3:31 AMVivek Sharma
01/26/2021, 5:44 AMModalBottomSheetLayout
, by default it may be expanding till half of the screen height, but I controlled the height by including my custom layout in sheetContent
lambda param in ModalBottomSheetLayout
,
you can add your custom layout composable inside that and have fillMaxHeight()
or get the screen height using WithConstraint
Utkarsh Tiwari
01/26/2021, 8:01 AMsheetContent
, however, I want to make the modal cover only half the height of the screen if it’s Half Modal
and full screen if it’s Full Modal
. It doesn’t work thoughjossiwolf
01/26/2021, 9:35 AMHalfExpanded
state isn't supported (that is also the way the Material Design Guidelines describe it). Thus I suspect this won't get added.
What you can do is call ModalBottomSheetState#animateTo
with the desired target value when the ModalBottomSheetState#targetValue
is HalfExpanded
. Something like this:
with(state) {
val isOpening = value == ModalBottomSheetValue.Hidden &&
targetValue == ModalBottomSheetValue.HalfExpanded
val isClosing = value == ModalBottomSheetValue.Expanded &&
targetValue == ModalBottomSheetValue.HalfExpanded
when {
isOpening -> animateTo(ModalBottomSheetValue.Expanded)
isClosing -> animateTo(ModalBottomSheetValue.Hidden)
}
}
jossiwolf
01/26/2021, 10:36 AMVivek Sharma
01/26/2021, 10:40 AMUtkarsh Tiwari
01/27/2021, 4:33 AMUtkarsh Tiwari
01/27/2021, 12:22 PMUtkarsh Tiwari
01/27/2021, 12:23 PM@ExperimentalMaterialApi
@Composable
private fun SetupModals() {
var modalType: ModalType by remember { mutableStateOf(ModalType.HALF) }
val modalState = rememberModalState(initialValue = ModalStateValue.Hidden)
Modal(
title = "タイトル",
type = modalType,
state = modalState,
onActionClick = {},
onNavigationClick = {
modalState.hide()
},
modalContent = {
emptyContent()
}
) {
Screen(
onHalfModalButtonClick = {
modalType = ModalType.HALF
modalState.show()
},
onFullModalButtonClick = {
modalType = ModalType.FULL
modalState.show()
}
)
}
}
Utkarsh Tiwari
01/27/2021, 12:24 PMjossiwolf
01/28/2021, 8:35 AMUtkarsh Tiwari
01/29/2021, 4:39 AMDid that happen after skipping the half expanded state?No, it happens even if I don’t skip it.
Utkarsh Tiwari
01/29/2021, 4:53 AMjossiwolf
01/29/2021, 10:21 AMonClick
is being called
• Step into the show
method in your state + set a breakpoint in the onEnd
lambda. Then take a look at the endReason
. If it's Interrupted
, something weird is going on 😄