Improve insets handling
This commit is contained in:
parent
6fb377d743
commit
d363f35801
2 changed files with 31 additions and 30 deletions
|
@ -14,17 +14,16 @@ import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
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.WindowInsetsSides
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
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.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.navigationBars
|
import androidx.compose.foundation.layout.only
|
||||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
|
||||||
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.systemBars
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.text.BasicText
|
import androidx.compose.foundation.text.BasicText
|
||||||
import androidx.compose.runtime.Composable
|
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.geometry.Offset
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
|
@ -81,7 +79,6 @@ fun Player(
|
||||||
|
|
||||||
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
||||||
val binder = LocalPlayerServiceBinder.current
|
val binder = LocalPlayerServiceBinder.current
|
||||||
val layoutDirection = LocalLayoutDirection.current
|
|
||||||
|
|
||||||
binder?.player ?: return
|
binder?.player ?: return
|
||||||
|
|
||||||
|
@ -92,6 +89,11 @@ fun Player(
|
||||||
val shouldBePlaying by rememberShouldBePlaying(binder.player)
|
val shouldBePlaying by rememberShouldBePlaying(binder.player)
|
||||||
val positionAndDuration by rememberPositionAndDuration(binder.player)
|
val positionAndDuration by rememberPositionAndDuration(binder.player)
|
||||||
|
|
||||||
|
val windowInsets = WindowInsets.systemBars
|
||||||
|
|
||||||
|
val horizontalBottomPaddingValues = windowInsets
|
||||||
|
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom).asPaddingValues()
|
||||||
|
|
||||||
OnGlobalRoute {
|
OnGlobalRoute {
|
||||||
layoutState.collapseSoft()
|
layoutState.collapseSoft()
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,7 @@ fun Player(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(colorPalette.background1)
|
.background(colorPalette.background1)
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.navigationBarsPadding()
|
.padding(horizontalBottomPaddingValues)
|
||||||
.drawBehind {
|
.drawBehind {
|
||||||
val progress =
|
val progress =
|
||||||
positionAndDuration.first.toFloat() / positionAndDuration.second.absoluteValue
|
positionAndDuration.first.toFloat() / positionAndDuration.second.absoluteValue
|
||||||
|
@ -217,20 +219,19 @@ fun Player(
|
||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val paddingValues = WindowInsets.navigationBars.asPaddingValues()
|
|
||||||
val playerBottomSheetState = rememberBottomSheetState(
|
val playerBottomSheetState = rememberBottomSheetState(
|
||||||
64.dp + paddingValues.calculateBottomPadding(),
|
64.dp + horizontalBottomPaddingValues.calculateBottomPadding(),
|
||||||
layoutState.expandedBound
|
layoutState.expandedBound
|
||||||
)
|
)
|
||||||
|
|
||||||
val containerModifier = Modifier
|
val containerModifier = Modifier
|
||||||
.background(colorPalette.background1)
|
.background(colorPalette.background1)
|
||||||
.padding(
|
.padding(
|
||||||
top = paddingValues.calculateTopPadding(),
|
windowInsets
|
||||||
start = paddingValues.calculateStartPadding(layoutDirection),
|
.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal)
|
||||||
end = paddingValues.calculateEndPadding(layoutDirection),
|
.asPaddingValues()
|
||||||
bottom = playerBottomSheetState.collapsedBound
|
|
||||||
)
|
)
|
||||||
|
.padding(bottom = playerBottomSheetState.collapsedBound)
|
||||||
|
|
||||||
val thumbnailContent: @Composable (modifier: Modifier) -> Unit = { modifier ->
|
val thumbnailContent: @Composable (modifier: Modifier) -> Unit = { modifier ->
|
||||||
Thumbnail(
|
Thumbnail(
|
||||||
|
|
|
@ -11,15 +11,13 @@ import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.BoxScope
|
import androidx.compose.foundation.layout.BoxScope
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
import androidx.compose.foundation.layout.WindowInsetsSides
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
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.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.navigationBarsPadding
|
import androidx.compose.foundation.layout.only
|
||||||
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.systemBars
|
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.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.valentinilk.shimmer.shimmer
|
import com.valentinilk.shimmer.shimmer
|
||||||
|
@ -80,6 +77,11 @@ fun Queue(
|
||||||
) {
|
) {
|
||||||
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
||||||
|
|
||||||
|
val windowInsets = WindowInsets.systemBars
|
||||||
|
|
||||||
|
val horizontalBottomPaddingValues = windowInsets
|
||||||
|
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Bottom).asPaddingValues()
|
||||||
|
|
||||||
BottomSheet(
|
BottomSheet(
|
||||||
state = layoutState,
|
state = layoutState,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
@ -88,7 +90,7 @@ fun Queue(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.drawBehind { drawRect(backgroundColorProvider()) }
|
.drawBehind { drawRect(backgroundColorProvider()) }
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.navigationBarsPadding()
|
.padding(horizontalBottomPaddingValues)
|
||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(R.drawable.playlist),
|
painter = painterResource(R.drawable.playlist),
|
||||||
|
@ -104,7 +106,6 @@ fun Queue(
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
val binder = LocalPlayerServiceBinder.current
|
val binder = LocalPlayerServiceBinder.current
|
||||||
val layoutDirection = LocalLayoutDirection.current
|
|
||||||
|
|
||||||
binder?.player ?: return@BottomSheet
|
binder?.player ?: return@BottomSheet
|
||||||
|
|
||||||
|
@ -124,19 +125,15 @@ fun Queue(
|
||||||
extraItemCount = 0
|
extraItemCount = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
val paddingValues = WindowInsets.systemBars.asPaddingValues()
|
|
||||||
val bottomPadding = paddingValues.calculateBottomPadding()
|
|
||||||
|
|
||||||
val rippleIndication = rememberRipple(bounded = false)
|
val rippleIndication = rememberRipple(bounded = false)
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
ReorderingLazyColumn(
|
ReorderingLazyColumn(
|
||||||
reorderingState = reorderingState,
|
reorderingState = reorderingState,
|
||||||
contentPadding = PaddingValues(
|
contentPadding = windowInsets
|
||||||
top = paddingValues.calculateTopPadding(),
|
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top).asPaddingValues(),
|
||||||
start = paddingValues.calculateStartPadding(layoutDirection),
|
|
||||||
end = paddingValues.calculateEndPadding(layoutDirection),
|
|
||||||
),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(colorPalette.background0)
|
.background(colorPalette.background0)
|
||||||
|
@ -197,7 +194,10 @@ fun Queue(
|
||||||
indication = rippleIndication,
|
indication = rippleIndication,
|
||||||
onClick = {},
|
onClick = {},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.reorder(reorderingState = reorderingState, index = window.firstPeriodIndex)
|
.reorder(
|
||||||
|
reorderingState = reorderingState,
|
||||||
|
index = window.firstPeriodIndex
|
||||||
|
)
|
||||||
.size(18.dp)
|
.size(18.dp)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -256,11 +256,11 @@ fun Queue(
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable(onClick = layoutState::collapseSoft)
|
.clickable(onClick = layoutState::collapseSoft)
|
||||||
.height(64.dp + bottomPadding)
|
|
||||||
.background(colorPalette.background2)
|
.background(colorPalette.background2)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 12.dp)
|
.padding(horizontal = 12.dp)
|
||||||
.padding(bottom = bottomPadding)
|
.padding(horizontalBottomPaddingValues)
|
||||||
|
.height(64.dp)
|
||||||
) {
|
) {
|
||||||
BasicText(
|
BasicText(
|
||||||
text = "${windows.size} songs",
|
text = "${windows.size} songs",
|
||||||
|
|
Loading…
Reference in a new issue