11package top.yukonga.miuix.kmp.basic
22
33import androidx.compose.foundation.layout.Box
4+ import androidx.compose.foundation.layout.WindowInsets
5+ import androidx.compose.foundation.layout.WindowInsetsSides
46import 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
511import androidx.compose.foundation.shape.RoundedCornerShape
612import androidx.compose.runtime.Composable
713import androidx.compose.ui.Alignment
@@ -11,6 +17,7 @@ import androidx.compose.ui.graphics.Shape
1117import androidx.compose.ui.semantics.Role
1218import androidx.compose.ui.semantics.role
1319import androidx.compose.ui.semantics.semantics
20+ import androidx.compose.ui.unit.Dp
1421import androidx.compose.ui.unit.dp
1522import 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