Skip to content

Commit de38e97

Browse files
committed
library: Add defaultWindowInsetsPadding to FloatingActionButton
1 parent e02f70b commit de38e97

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/FloatingActionButton.kt

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package top.yukonga.miuix.kmp.basic
22

33
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.foundation.layout.WindowInsets
5+
import androidx.compose.foundation.layout.WindowInsetsSides
46
import androidx.compose.foundation.layout.defaultMinSize
7+
import androidx.compose.foundation.layout.displayCutout
8+
import androidx.compose.foundation.layout.navigationBars
9+
import androidx.compose.foundation.layout.only
10+
import androidx.compose.foundation.layout.windowInsetsPadding
511
import androidx.compose.foundation.shape.RoundedCornerShape
612
import androidx.compose.runtime.Composable
713
import androidx.compose.ui.Alignment
@@ -11,6 +17,7 @@ import androidx.compose.ui.graphics.Shape
1117
import androidx.compose.ui.semantics.Role
1218
import androidx.compose.ui.semantics.role
1319
import androidx.compose.ui.semantics.semantics
20+
import androidx.compose.ui.unit.Dp
1421
import androidx.compose.ui.unit.dp
1522
import top.yukonga.miuix.kmp.theme.MiuixTheme
1623

@@ -22,6 +29,9 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
2229
* @param shape The shape of the [FloatingActionButton].
2330
* @param containerColor The color of the [FloatingActionButton].
2431
* @param shadowElevation The shadow elevation of the [FloatingActionButton].
32+
* @param minWidth The minimum width of the [FloatingActionButton].
33+
* @param minHeight The minimum height of the [FloatingActionButton].
34+
* @param defaultWindowInsetsPadding Whether to apply default window insets padding to the [FloatingActionButton].
2535
* @param content The [Composable] content of the [FloatingActionButton].
2636
*/
2737
@Composable
@@ -31,21 +41,30 @@ fun FloatingActionButton(
3141
shape: Shape = RoundedCornerShape(60.dp),
3242
containerColor: Color = MiuixTheme.colorScheme.primary,
3343
shadowElevation: Float = 18.0f,
44+
minWidth: Dp = 60.dp,
45+
minHeight: Dp = 60.dp,
46+
defaultWindowInsetsPadding: Boolean = true,
3447
content: @Composable () -> Unit,
3548
) {
3649
Surface(
3750
onClick = onClick,
38-
modifier = modifier.semantics { role = Role.Button },
51+
modifier = if (defaultWindowInsetsPadding) {
52+
modifier
53+
.windowInsetsPadding(WindowInsets.displayCutout.only(WindowInsetsSides.Horizontal))
54+
.windowInsetsPadding(WindowInsets.navigationBars.only(WindowInsetsSides.Horizontal))
55+
} else {
56+
modifier
57+
}.semantics { role = Role.Button },
3958
shape = shape,
4059
color = containerColor,
4160
shadowElevation = shadowElevation
4261
) {
4362
Box(
44-
modifier =
45-
Modifier.defaultMinSize(
46-
minWidth = 60.dp,
47-
minHeight = 60.dp,
48-
),
63+
modifier = Modifier
64+
.defaultMinSize(
65+
minWidth = minWidth,
66+
minHeight = minHeight,
67+
),
4968
contentAlignment = Alignment.Center,
5069
) {
5170
content()

0 commit comments

Comments
 (0)