Skip to content

Commit

Permalink
Use safe drawing insets
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPushkin committed May 17, 2024
1 parent f6dab17 commit 94e38e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/ru/spbu/depnav/ui/component/MapSearchBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
Expand Down Expand Up @@ -95,7 +95,7 @@ fun MapSearchBar(
label = "Map search bar activation animation progress"
)

val (insetsStartPadding, insetsEndPadding) = with(WindowInsets.systemBars.asPaddingValues()) {
val (insetsStartPadding, insetsEndPadding) = with(WindowInsets.safeDrawing.asPaddingValues()) {
val layoutDirection = LocalLayoutDirection.current
calculateStartPadding(layoutDirection) to calculateEndPadding(layoutDirection)
}
Expand All @@ -116,7 +116,7 @@ fun MapSearchBar(
modifier = Modifier
.run {
if (active) padding(start = outerStartPadding, end = outerEndPadding)
else windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal))
else windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal))
}
.then(modifier),
placeholder = {
Expand Down Expand Up @@ -157,7 +157,7 @@ fun MapSearchBar(
.padding(
start = innerStartPadding,
end = innerEndPadding,
bottom = WindowInsets.systemBars
bottom = WindowInsets.safeDrawing
.asPaddingValues()
.calculateBottomPadding()
)
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/ru/spbu/depnav/ui/screen/MapScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import androidx.compose.foundation.layout.exclude
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.shape.CornerSize
Expand Down Expand Up @@ -268,7 +268,7 @@ private fun BoxScope.AnimatedFloorSwitch(
visible = visible,
modifier = Modifier
.align(Alignment.TopEnd)
.safeContentPadding()
.safeDrawingPadding()
.padding(top = 64.dp) // Estimated search bar height
.padding(DEFAULT_PADDING),
enter = slideInHorizontally(initialOffsetX = horizontalOffset) + fadeIn(),
Expand All @@ -293,7 +293,7 @@ private fun BoxScope.AnimatedBottom(pinnedMarker: MarkerWithText?, showZoomInHin
) {
Surface(
modifier = Modifier
.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal))
.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal))
.width(640.dp),
shape = MaterialTheme.shapes.large.copy(
bottomStart = CornerSize(0),
Expand All @@ -320,7 +320,9 @@ private fun BoxScope.AnimatedBottom(pinnedMarker: MarkerWithText?, showZoomInHin
description = markerText.description,
modifier = Modifier
.padding(DEFAULT_PADDING)
.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Bottom))
.windowInsetsPadding(
WindowInsets.safeDrawing.only(WindowInsetsSides.Bottom)
)
) {
MarkerView(
title = markerText.title ?: stringResource(R.string.no_title),
Expand All @@ -337,7 +339,7 @@ private fun BoxScope.AnimatedBottom(pinnedMarker: MarkerWithText?, showZoomInHin
modifier = Modifier
.align(Alignment.BottomCenter)
.windowInsetsPadding(
WindowInsets.systemBars.run { exclude(only(WindowInsetsSides.Top)) }
WindowInsets.safeDrawing.run { exclude(only(WindowInsetsSides.Top)) }
),
enter = fadeIn(),
exit = fadeOut()
Expand Down

0 comments on commit 94e38e0

Please sign in to comment.