Skip to content

Commit e4c227c

Browse files
Limit the sheet height to the bottom of the status bar
1 parent ccd5986 commit e4c227c

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/bottomsheet/GravatarQuickEditorBottomSheet.kt

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import android.content.res.Configuration
44
import android.graphics.Color
55
import androidx.compose.foundation.background
66
import androidx.compose.foundation.isSystemInDarkTheme
7+
import androidx.compose.foundation.layout.Box
78
import androidx.compose.foundation.layout.Column
9+
import androidx.compose.foundation.layout.PaddingValues
810
import androidx.compose.foundation.layout.WindowInsets
911
import androidx.compose.foundation.layout.WindowInsetsSides
1012
import androidx.compose.foundation.layout.asPaddingValues
@@ -13,6 +15,7 @@ import androidx.compose.foundation.layout.imePadding
1315
import androidx.compose.foundation.layout.navigationBars
1416
import androidx.compose.foundation.layout.only
1517
import androidx.compose.foundation.layout.padding
18+
import androidx.compose.foundation.layout.statusBars
1619
import androidx.compose.foundation.layout.widthIn
1720
import androidx.compose.foundation.shape.RoundedCornerShape
1821
import androidx.compose.material3.MaterialTheme
@@ -261,36 +264,49 @@ private fun GravatarModalBottomSheet(
261264
Scrim(
262265
scrimColor = MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f),
263266
)
264-
Sheet(
267+
Box(
265268
modifier = Modifier
266-
.imePadding()
267-
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
268-
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
269-
.widthIn(max = 640.dp)
270-
.fillMaxWidth()
271269
.padding(
272-
WindowInsets.navigationBars
273-
.only(WindowInsetsSides.Vertical)
274-
.asPaddingValues(),
270+
paddingValues = if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
271+
PaddingValues(0.dp)
272+
} else {
273+
WindowInsets.statusBars
274+
.only(WindowInsetsSides.Top)
275+
.asPaddingValues()
276+
},
275277
),
276278
) {
277-
val window = LocalModalWindow.current
278-
val isDarkTheme = isSystemInDarkTheme()
279-
LaunchedEffect(Unit) {
280-
window.navigationBarColor = Color.TRANSPARENT
281-
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightNavigationBars =
282-
!isDarkTheme
283-
}
284-
Surface(
279+
Sheet(
285280
modifier = Modifier
286-
.fillMaxWidth(),
287-
tonalElevation = 1.dp,
281+
.imePadding()
282+
.clip(RoundedCornerShape(topStart = 28.dp, topEnd = 28.dp))
283+
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp))
284+
.widthIn(max = 640.dp)
285+
.fillMaxWidth()
286+
.padding(
287+
WindowInsets.navigationBars
288+
.only(WindowInsetsSides.Vertical)
289+
.asPaddingValues(),
290+
),
288291
) {
289-
Column(
290-
horizontalAlignment = Alignment.CenterHorizontally,
292+
val window = LocalModalWindow.current
293+
val isDarkTheme = isSystemInDarkTheme()
294+
LaunchedEffect(Unit) {
295+
window.navigationBarColor = Color.TRANSPARENT
296+
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightNavigationBars =
297+
!isDarkTheme
298+
}
299+
Surface(
300+
modifier = Modifier
301+
.fillMaxWidth(),
302+
tonalElevation = 1.dp,
291303
) {
292-
QEDragHandle()
293-
content()
304+
Column(
305+
horizontalAlignment = Alignment.CenterHorizontally,
306+
) {
307+
QEDragHandle()
308+
content()
309+
}
294310
}
295311
}
296312
}
@@ -300,12 +316,11 @@ private fun GravatarModalBottomSheet(
300316
}
301317
}
302318

303-
internal val peek = SheetDetent(identifier = "peek") { containerHeight, _ ->
304-
containerHeight * 0.6f
305-
}
306-
307319
@Composable
308320
internal fun AvatarPickerContentLayout.modalDetents(): ModalDetents {
321+
val peek = SheetDetent(identifier = "peek") { containerHeight, sheetHeight ->
322+
containerHeight * 0.6f
323+
}
309324
val windowHeightSizeClass = currentWindowAdaptiveInfo().windowSizeClass.windowHeightSizeClass
310325
val initialDetent = if (windowHeightSizeClass == WindowHeightSizeClass.COMPACT) {
311326
FullyExpanded

0 commit comments

Comments
 (0)