Skip to content

Commit 7d9ecbc

Browse files
committed
library: SuperBottomSheet: Optimize the WindowInsets area
1 parent 5056104 commit 7d9ecbc

File tree

4 files changed

+57
-46
lines changed

4 files changed

+57
-46
lines changed

example/src/commonMain/kotlin/component/TextComponent.kt

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
1818
import androidx.compose.foundation.layout.navigationBars
1919
import androidx.compose.foundation.layout.padding
2020
import androidx.compose.foundation.layout.width
21+
import androidx.compose.foundation.lazy.LazyColumn
2122
import androidx.compose.runtime.Composable
2223
import androidx.compose.runtime.MutableState
2324
import androidx.compose.runtime.getValue
@@ -507,48 +508,52 @@ fun BottomSheet(
507508
}
508509
}
509510
) {
510-
var progress by remember { mutableStateOf(0.5f) }
511-
Slider(
512-
progress = progress,
513-
onProgressChange = { newProgress -> progress = newProgress },
514-
decimalPlaces = 3,
515-
modifier = Modifier.padding(bottom = 12.dp)
516-
)
517-
Card(
518-
modifier = Modifier.padding(bottom = 12.dp),
519-
colors = CardDefaults.defaultColors(
520-
color = MiuixTheme.colorScheme.secondaryContainer,
521-
)
522-
) {
523-
SuperDropdown(
524-
title = "Dropdown",
525-
items = dropdownOptions,
526-
selectedIndex = bottomSheetDropdownSelectedOption.value,
527-
onSelectedIndexChange = { newOption -> bottomSheetDropdownSelectedOption.value = newOption }
528-
)
529-
SuperSwitch(
530-
title = "Switch",
531-
checked = bottomSheetSuperSwitchState.value,
532-
onCheckedChange = {
533-
bottomSheetSuperSwitchState.value = it
511+
LazyColumn {
512+
item {
513+
var progress by remember { mutableStateOf(0.5f) }
514+
Slider(
515+
progress = progress,
516+
onProgressChange = { newProgress -> progress = newProgress },
517+
decimalPlaces = 3,
518+
modifier = Modifier.padding(bottom = 12.dp)
519+
)
520+
Card(
521+
modifier = Modifier.padding(bottom = 12.dp),
522+
colors = CardDefaults.defaultColors(
523+
color = MiuixTheme.colorScheme.secondaryContainer,
524+
)
525+
) {
526+
SuperDropdown(
527+
title = "Dropdown",
528+
items = dropdownOptions,
529+
selectedIndex = bottomSheetDropdownSelectedOption.value,
530+
onSelectedIndexChange = { newOption -> bottomSheetDropdownSelectedOption.value = newOption }
531+
)
532+
SuperSwitch(
533+
title = "Switch",
534+
checked = bottomSheetSuperSwitchState.value,
535+
onCheckedChange = {
536+
bottomSheetSuperSwitchState.value = it
537+
}
538+
)
534539
}
535-
)
536-
}
537-
AnimatedVisibility(
538-
visible = bottomSheetSuperSwitchState.value,
539-
enter = fadeIn() + expandVertically(),
540-
exit = fadeOut() + shrinkVertically()
541-
) {
542-
val miuixColor = MiuixTheme.colorScheme.primary
543-
var selectedColor by remember { mutableStateOf(miuixColor) }
544-
ColorPalette(
545-
modifier = Modifier.padding(bottom = 12.dp),
546-
initialColor = selectedColor,
547-
onColorChanged = { selectedColor = it },
548-
showPreview = false
549-
)
540+
AnimatedVisibility(
541+
visible = bottomSheetSuperSwitchState.value,
542+
enter = fadeIn() + expandVertically(),
543+
exit = fadeOut() + shrinkVertically()
544+
) {
545+
val miuixColor = MiuixTheme.colorScheme.primary
546+
var selectedColor by remember { mutableStateOf(miuixColor) }
547+
ColorPalette(
548+
modifier = Modifier.padding(bottom = 12.dp),
549+
initialColor = selectedColor,
550+
onColorChanged = { selectedColor = it },
551+
showPreview = false
552+
)
553+
}
554+
Spacer(Modifier.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()))
555+
}
550556
}
551-
Spacer(Modifier.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()))
552557
}
553558
}
554559

iosApp/iosApp/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundleShortVersionString</key>
1818
<string>1.0.5</string>
1919
<key>CFBundleVersion</key>
20-
<string>567</string>
20+
<string>568</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
2323
<key>CADisableMinimumFrameDurationOnPhone</key>

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperBottomSheet.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import androidx.compose.foundation.gestures.detectVerticalDragGestures
1111
import androidx.compose.foundation.layout.Box
1212
import androidx.compose.foundation.layout.Column
1313
import androidx.compose.foundation.layout.WindowInsets
14+
import androidx.compose.foundation.layout.asPaddingValues
15+
import androidx.compose.foundation.layout.captionBar
16+
import androidx.compose.foundation.layout.displayCutout
1417
import androidx.compose.foundation.layout.fillMaxSize
1518
import androidx.compose.foundation.layout.fillMaxWidth
1619
import androidx.compose.foundation.layout.height
@@ -179,9 +182,10 @@ private fun SuperBottomSheetContent(
179182
derivedStateOf { windowSize.height.dp / density.density }
180183
}
181184

182-
val statusBarHeight = with(density) {
183-
WindowInsets.statusBars.getTop(density).toDp()
184-
}
185+
val statusBars = WindowInsets.statusBars.asPaddingValues().calculateTopPadding()
186+
val captionBar = WindowInsets.captionBar.asPaddingValues().calculateTopPadding()
187+
val displayCutout = WindowInsets.displayCutout.asPaddingValues().calculateTopPadding()
188+
val statusBarHeight = remember { maxOf(statusBars, captionBar, displayCutout) }
185189

186190
val rootBoxModifier = Modifier
187191
.pointerInput(onDismissRequest) {
@@ -261,7 +265,7 @@ private fun SuperBottomSheetColumn(
261265
.align(Alignment.BottomCenter)
262266
.widthIn(max = sheetMaxWidth)
263267
.fillMaxWidth()
264-
.height(with(density) { overscrollOffsetPx.toDp() })
268+
.height(with(density) { overscrollOffsetPx.toDp() } + 1.dp)
265269
.padding(horizontal = outsideMargin.width)
266270
.background(backgroundColor)
267271
)

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDialog.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ private fun SuperDialogContent(
174174
val rootBoxModifier = Modifier
175175
.then(
176176
if (defaultWindowInsetsPadding)
177-
Modifier.imePadding().navigationBarsPadding()
177+
Modifier
178+
.imePadding()
179+
.navigationBarsPadding()
178180
else
179181
Modifier
180182
)

0 commit comments

Comments
 (0)