shock 11
07/19/2024, 11:55 AMshock 11
07/19/2024, 11:58 AM@Composable
fun Tray(
onDismissRequest: OptionalButtonCallback,
isSwipeDismissible: Boolean = true,
skipPartiallyExpanded: Boolean = false,
stickyBottom: (@Composable BoxScope.() -> Unit)? = null,
content: @Composable BoxScope.() -> Unit,
) {
val sheetState = rememberModalBottomSheetState(confirmValueChange = { isSwipeDismissible }, skipPartiallyExpanded = skipPartiallyExpanded)
val bottomPadding = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
BaseModelBottomSheet(
onDismissRequest = {
onDismissRequest?.invoke()
},
sheetState = sheetState,
) {
Box(
modifier = Modifier
.imePadding() // does not work. The keyboard covers the content of the BottomSheet
.padding(bottom = bottomPadding),
contentAlignment = Alignment.BottomEnd
) {
content()
stickyBottom?.let { stickyBottom ->
Box(modifier = Modifier
.wrapContentWidth()
.padding(Theme.spacing.x5)
.offset {
IntOffset(x = 0, y = -sheetState.requireOffset().toInt())
}) {
stickyBottom()
}
}
}
}
}
Stylianos Gakis
07/19/2024, 12:04 PMSheet() {
Column(verticalScroll) {
NormalSheetContent()
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.ime))
}
}
but you may also need to be careful not to double-apply the insets, depending on what insets you pass to your Sheet itself.
Play around with this idea to see if it helps you or not.
Oh and if you do not have android:windowSoftInputMode="adjustResize"
then things may be very different overall, but I don't know how that works, I only really know how insets work with adjustResize.shock 11
07/19/2024, 1:04 PMStylianos Gakis
07/19/2024, 1:10 PMSpacer(Modifier.windowInsetsBottomHeight(WindowInsets.ime))
, you may end up applying the ime insets both on the sheet and on this spacer too. So I'd check what insets you pass to the sheet itself too. Even if you pass none, it has some default ones iircshock 11
07/19/2024, 1:25 PMval bottomPadding = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
// and then in the composable, the direct sheet's Box content
Box(
modifier = Modifier
.imePadding() // does not work. The keyboard covers the content of the BottomSheet
.padding(bottom = bottomPadding), // bottom padding applied here
contentAlignment = Alignment.BottomEnd
)
shock 11
07/19/2024, 1:25 PMshock 11
07/19/2024, 3:53 PMTray(
onDismissRequest = { viewModel.emit(Intent.Navigation.Back) }
) {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(horizontal = Theme.spacing.x4),
horizontalAlignment = Alignment.CenterHorizontally
) {
// Some screen content including the TextFields
Spacer(
modifier = Modifier.windowInsetsBottomHeight(WindowInsets.ime) // keyboard still covers the content
)
}
}
Stylianos Gakis
07/19/2024, 4:05 PMshock 11
07/19/2024, 4:11 PMStylianos Gakis
07/19/2024, 4:13 PMshock 11
07/19/2024, 4:16 PMshock 11
07/19/2024, 4:21 PMSpacer(
modifier = Modifier
.windowInsetsBottomHeight(WindowInsets.ime)
.onPlaced {
Log.i("CreateChildScreen", "The height of the spacer is ${it.size.height}")
}
)
shock 11
07/19/2024, 4:37 PMStylianos Gakis
07/19/2024, 4:43 PMshock 11
07/19/2024, 4:44 PMStylianos Gakis
07/19/2024, 4:46 PMshock 11
07/19/2024, 4:47 PMshock 11
07/19/2024, 4:51 PM@Composable
fun Tray(
onDismissRequest: OptionalButtonCallback,
isSwipeDismissible: Boolean = true,
skipPartiallyExpanded: Boolean = false,
stickyBottom: (@Composable BoxScope.() -> Unit)? = null,
content: @Composable BoxScope.() -> Unit,
) {
val sheetState = rememberModalBottomSheetState(confirmValueChange = { isSwipeDismissible }, skipPartiallyExpanded = skipPartiallyExpanded)
val bottomPadding = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
BaseModelBottomSheet(
onDismissRequest = {
onDismissRequest?.invoke()
},
sheetState = sheetState,
) {
Box(
modifier = Modifier
.padding(bottom = bottomPadding),
contentAlignment = Alignment.BottomEnd
) {
content()
stickyBottom?.let { stickyBottom ->
Box(modifier = Modifier
.wrapContentWidth()
.padding(horizontal = Theme.spacing.x5)
.offset {
IntOffset(x = 0, y = -sheetState.requireOffset().toInt())
}) {
stickyBottom()
}
}
}
}
}
shock 11
07/19/2024, 4:52 PMshock 11
07/19/2024, 4:53 PM@Composable
internal fun BaseModelBottomSheet(
modifier: Modifier = Modifier,
sheetState: SheetState,
onDismissRequest: OptionalButtonCallback,
invertedColors: Boolean = isSystemInDarkTheme(),
content: @Composable ColumnScope.() -> Unit,
) {
ModalBottomSheet(
containerColor = componentColors(invertedColors = invertedColors),
onDismissRequest = {
onDismissRequest?.invoke()
},
sheetState = sheetState,
modifier = modifier,
windowInsets = WindowInsets(0.dp)
) {
content()
}
}
Stylianos Gakis
07/19/2024, 4:55 PMshock 11
07/19/2024, 4:57 PMshock 11
07/19/2024, 5:12 PMshock 11
07/19/2024, 5:13 PMshock 11
07/19/2024, 5:56 PMStylianos Gakis
07/19/2024, 6:06 PMshock 11
07/19/2024, 7:01 PMshock 11
07/19/2024, 7:02 PMshock 11
07/19/2024, 8:43 PMshock 11
07/19/2024, 8:43 PMshock 11
07/19/2024, 8:43 PM