Skip to content

Commit b595608

Browse files
committed
library: Fix navigation bar click penetration
1 parent fcb2a98 commit b595608

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import androidx.compose.foundation.layout.asPaddingValues
1515
import androidx.compose.foundation.layout.captionBar
1616
import androidx.compose.foundation.layout.fillMaxWidth
1717
import androidx.compose.foundation.layout.height
18-
import androidx.compose.foundation.layout.navigationBarsPadding
18+
import androidx.compose.foundation.layout.navigationBars
1919
import androidx.compose.foundation.layout.only
2020
import androidx.compose.foundation.layout.padding
2121
import androidx.compose.foundation.layout.size
@@ -49,6 +49,7 @@ import top.yukonga.miuix.kmp.utils.platform
4949
* @param onClick The callback when the item of the [NavigationBar] is clicked.
5050
* @param modifier The modifier to be applied to the [NavigationBar].
5151
* @param color The color of the [NavigationBar].
52+
* @param showDivider Whether to show the divider line between the [NavigationBar] and the content.
5253
* @param defaultWindowInsetsPadding whether to apply default window insets padding to the [NavigationBar].
5354
*/
5455
@Composable
@@ -58,6 +59,7 @@ fun NavigationBar(
5859
onClick: (Int) -> Unit,
5960
modifier: Modifier = Modifier,
6061
color: Color = MiuixTheme.colorScheme.surfaceContainer,
62+
showDivider: Boolean = true,
6163
defaultWindowInsetsPadding: Boolean = true
6264
) {
6365
require(items.size in 2..5) { "BottomBar must have between 2 and 5 items" }
@@ -68,25 +70,22 @@ fun NavigationBar(
6870
targetValue = if (captionBarBottomPadding > 0.dp) captionBarBottomPadding else 0.dp,
6971
animationSpec = tween(durationMillis = 300)
7072
)
71-
Surface(color = color) {
73+
Surface(
74+
color = color
75+
) {
7276
Column(
73-
modifier = if (defaultWindowInsetsPadding) {
74-
modifier
75-
.navigationBarsPadding()
76-
.padding(bottom = animatedCaptionBarHeight)
77-
} else {
78-
modifier
79-
}
77+
modifier = modifier
8078
.fillMaxWidth()
8179
.background(Color.Transparent)
8280
) {
83-
HorizontalDivider(
84-
thickness = 0.75.dp,
85-
color = MiuixTheme.colorScheme.dividerLine
86-
)
81+
if (showDivider) {
82+
HorizontalDivider(
83+
thickness = 0.75.dp,
84+
color = MiuixTheme.colorScheme.dividerLine
85+
)
86+
}
8787
Row(
88-
modifier = Modifier
89-
.fillMaxWidth(),
88+
modifier = Modifier.fillMaxWidth(),
9089
horizontalArrangement = Arrangement.SpaceBetween,
9190
verticalAlignment = Alignment.CenterVertically
9291
) {
@@ -107,10 +106,17 @@ fun NavigationBar(
107106
)
108107
val fontWeight = if (isSelected) FontWeight.Medium else FontWeight.Normal
109108
Column(
110-
horizontalAlignment = Alignment.CenterHorizontally,
111-
modifier = Modifier
109+
modifier = if (defaultWindowInsetsPadding) {
110+
modifier
111+
.height(
112+
NavigationBarHeight
113+
+ WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
114+
+ animatedCaptionBarHeight
115+
)
116+
} else {
117+
modifier.height(NavigationBarHeight)
118+
}
112119
.weight(1f / items.size)
113-
.height(NavigationBarHeight)
114120
.pointerInput(Unit) {
115121
detectTapGestures(
116122
onPress = {
@@ -120,7 +126,8 @@ fun NavigationBar(
120126
},
121127
onTap = { onClick(index) }
122128
)
123-
}
129+
},
130+
horizontalAlignment = Alignment.CenterHorizontally
124131
) {
125132
Image(
126133
modifier = Modifier.size(32.dp).padding(top = 6.dp),
@@ -146,7 +153,6 @@ fun NavigationBar(
146153
/** The default expanded height of a [NavigationBar]. */
147154
val NavigationBarHeight: Dp = if (platform() != Platform.IOS) 64.dp else 48.dp
148155

149-
150156
/**
151157
* The data class for [NavigationBar].
152158
*

0 commit comments

Comments
 (0)