Respect IME insets in bottom sheet

This commit is contained in:
MM20 2023-08-26 22:47:00 +02:00
parent c0ba124ee6
commit f079974c10
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,5 @@
package de.mm20.launcher2.ui.component package de.mm20.launcher2.ui.component
import android.util.Log
import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring import androidx.compose.animation.core.spring
import androidx.compose.foundation.background import androidx.compose.foundation.background
@ -19,11 +18,11 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.systemBars
@ -173,7 +172,8 @@ fun BottomSheetDialog(
) { ) {
BoxWithConstraints( BoxWithConstraints(
modifier = Modifier modifier = Modifier
.fillMaxSize(), .fillMaxSize()
.imePadding(),
propagateMinConstraints = true, propagateMinConstraints = true,
contentAlignment = Alignment.BottomCenter contentAlignment = Alignment.BottomCenter
) { ) {
@ -346,14 +346,17 @@ private enum class SwipeState {
Full, Peek, Dismiss Full, Peek, Dismiss
} }
private class BottomSheetPositionProvider(val insets: WindowInsets, val density: Density): PopupPositionProvider { private class BottomSheetPositionProvider(val insets: WindowInsets, val density: Density) :
PopupPositionProvider {
override fun calculatePosition( override fun calculatePosition(
anchorBounds: IntRect, anchorBounds: IntRect,
windowSize: IntSize, windowSize: IntSize,
layoutDirection: LayoutDirection, layoutDirection: LayoutDirection,
popupContentSize: IntSize popupContentSize: IntSize
): IntOffset { ): IntOffset {
Log.d("MM20", "calculatePosition: anchorBounds=$anchorBounds, windowSize=$windowSize, layoutDirection=$layoutDirection, popupContentSize=$popupContentSize") return IntOffset.Zero + IntOffset(
return IntOffset.Zero + IntOffset(insets.getLeft(density, layoutDirection), insets.getTop(density)) insets.getLeft(density, layoutDirection),
insets.getTop(density)
)
} }
} }

View File

@ -8,6 +8,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AutoFixHigh import androidx.compose.material.icons.rounded.AutoFixHigh
import androidx.compose.material.icons.rounded.SettingsSuggest import androidx.compose.material.icons.rounded.SettingsSuggest
@ -60,7 +62,9 @@ fun CorePaletteColorPreference(
showDialog = false showDialog = false
}) { }) {
Column( Column(
modifier = Modifier.padding(it) modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(it)
) { ) {
SwitchPreference( SwitchPreference(
icon = Icons.Rounded.SettingsSuggest, icon = Icons.Rounded.SettingsSuggest,

View File

@ -13,7 +13,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Colorize import androidx.compose.material.icons.rounded.Colorize
import androidx.compose.material.icons.rounded.Palette import androidx.compose.material.icons.rounded.Palette
@ -91,6 +93,7 @@ fun ThemeColorPreference(
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.verticalScroll(rememberScrollState())
.padding(it), .padding(it),
) { ) {
SingleChoiceSegmentedButtonRow( SingleChoiceSegmentedButtonRow(