Improve insets handling

This commit is contained in:
vfsfitvnm 2022-10-08 12:32:12 +02:00
parent 6fb377d743
commit d363f35801
2 changed files with 31 additions and 30 deletions

View file

@ -14,17 +14,16 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
@ -39,7 +38,6 @@ import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.media3.common.MediaItem
@ -81,7 +79,6 @@ fun Player(
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
val binder = LocalPlayerServiceBinder.current
val layoutDirection = LocalLayoutDirection.current
binder?.player ?: return
@ -92,6 +89,11 @@ fun Player(
val shouldBePlaying by rememberShouldBePlaying(binder.player)
val positionAndDuration by rememberPositionAndDuration(binder.player)
val windowInsets = WindowInsets.systemBars
val horizontalBottomPaddingValues = windowInsets
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom).asPaddingValues()
OnGlobalRoute {
layoutState.collapseSoft()
}
@ -110,7 +112,7 @@ fun Player(
modifier = Modifier
.background(colorPalette.background1)
.fillMaxSize()
.navigationBarsPadding()
.padding(horizontalBottomPaddingValues)
.drawBehind {
val progress =
positionAndDuration.first.toFloat() / positionAndDuration.second.absoluteValue
@ -217,20 +219,19 @@ fun Player(
mutableStateOf(false)
}
val paddingValues = WindowInsets.navigationBars.asPaddingValues()
val playerBottomSheetState = rememberBottomSheetState(
64.dp + paddingValues.calculateBottomPadding(),
64.dp + horizontalBottomPaddingValues.calculateBottomPadding(),
layoutState.expandedBound
)
val containerModifier = Modifier
.background(colorPalette.background1)
.padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection),
bottom = playerBottomSheetState.collapsedBound
windowInsets
.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal)
.asPaddingValues()
)
.padding(bottom = playerBottomSheetState.collapsedBound)
val thumbnailContent: @Composable (modifier: Modifier) -> Unit = { modifier ->
Thumbnail(

View file

@ -11,15 +11,13 @@ import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
@ -38,7 +36,6 @@ import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.valentinilk.shimmer.shimmer
@ -80,6 +77,11 @@ fun Queue(
) {
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
val windowInsets = WindowInsets.systemBars
val horizontalBottomPaddingValues = windowInsets
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom).asPaddingValues()
BottomSheet(
state = layoutState,
modifier = modifier,
@ -88,7 +90,7 @@ fun Queue(
modifier = Modifier
.drawBehind { drawRect(backgroundColorProvider()) }
.fillMaxSize()
.navigationBarsPadding()
.padding(horizontalBottomPaddingValues)
) {
Image(
painter = painterResource(R.drawable.playlist),
@ -104,7 +106,6 @@ fun Queue(
}
) {
val binder = LocalPlayerServiceBinder.current
val layoutDirection = LocalLayoutDirection.current
binder?.player ?: return@BottomSheet
@ -124,19 +125,15 @@ fun Queue(
extraItemCount = 0
)
val paddingValues = WindowInsets.systemBars.asPaddingValues()
val bottomPadding = paddingValues.calculateBottomPadding()
val rippleIndication = rememberRipple(bounded = false)
Column {
ReorderingLazyColumn(
reorderingState = reorderingState,
contentPadding = PaddingValues(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection),
),
contentPadding = windowInsets
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top).asPaddingValues(),
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.background(colorPalette.background0)
@ -197,7 +194,10 @@ fun Queue(
indication = rippleIndication,
onClick = {},
modifier = Modifier
.reorder(reorderingState = reorderingState, index = window.firstPeriodIndex)
.reorder(
reorderingState = reorderingState,
index = window.firstPeriodIndex
)
.size(18.dp)
)
},
@ -256,11 +256,11 @@ fun Queue(
Box(
modifier = Modifier
.clickable(onClick = layoutState::collapseSoft)
.height(64.dp + bottomPadding)
.background(colorPalette.background2)
.fillMaxWidth()
.padding(horizontal = 12.dp)
.padding(bottom = bottomPadding)
.padding(horizontalBottomPaddingValues)
.height(64.dp)
) {
BasicText(
text = "${windows.size} songs",