Skip to content

Commit b2c4c60

Browse files
VoempYuKongA
andauthored
library: Fix some details (#14)
* Fix Button color * Remove animation when Switch/Checkbox is disabled * Fix NavigationBar height & text style * Fix TopAppBar height * Add haptic feedback for Popup options --------- Co-authored-by: 余空 <[email protected]>
1 parent 569e686 commit b2c4c60

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fun Button(
8080
@Composable
8181
private fun getButtonColor(enabled: Boolean, submit: Boolean): Color {
8282
return if (enabled) {
83-
if (submit) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.secondary
83+
if (submit) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.secondaryVariant
8484
} else {
8585
if (submit) MiuixTheme.colorScheme.disabledPrimaryButton else MiuixTheme.colorScheme.disabledSecondaryVariant
8686
}
@@ -89,7 +89,7 @@ private fun getButtonColor(enabled: Boolean, submit: Boolean): Color {
8989
@Composable
9090
private fun getTextColor(enabled: Boolean, submit: Boolean): Color {
9191
return if (enabled) {
92-
if (submit) Color.White else MiuixTheme.colorScheme.onBackground
92+
if (submit) MiuixTheme.colorScheme.onPrimary else MiuixTheme.colorScheme.onSecondaryVariant
9393
} else {
9494
if (submit) MiuixTheme.colorScheme.disabledOnPrimaryButton else MiuixTheme.colorScheme.disabledOnSecondaryVariant
9595
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fun Checkbox(
5757
var isPressed by remember { mutableStateOf(false) }
5858
val backgroundColor by animateColorAsState(if (isChecked) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.secondary)
5959
val disabledBackgroundColor by rememberUpdatedState(if (isChecked) MiuixTheme.colorScheme.disabledPrimary else MiuixTheme.colorScheme.disabledSecondary)
60-
val checkboxSize by animateDpAsState(if (isPressed) 20.dp else 22.dp)
60+
val checkboxSize by animateDpAsState(if (!enabled) 22.dp else if (isPressed) 20.dp else 22.dp)
6161
val checkmarkColor by animateColorAsState(if (checked) MiuixTheme.colorScheme.onPrimary else backgroundColor)
6262
val disabledCheckmarkColor by animateColorAsState(if (checked) MiuixTheme.colorScheme.disabledOnPrimary else disabledBackgroundColor)
6363
val rotationAngle by animateFloatAsState(

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.WindowInsetsSides
1414
import androidx.compose.foundation.layout.asPaddingValues
1515
import androidx.compose.foundation.layout.captionBar
1616
import androidx.compose.foundation.layout.fillMaxWidth
17+
import androidx.compose.foundation.layout.height
1718
import androidx.compose.foundation.layout.navigationBarsPadding
1819
import androidx.compose.foundation.layout.only
1920
import androidx.compose.foundation.layout.padding
@@ -31,7 +32,9 @@ import androidx.compose.ui.graphics.Color
3132
import androidx.compose.ui.graphics.ColorFilter
3233
import androidx.compose.ui.graphics.vector.ImageVector
3334
import androidx.compose.ui.input.pointer.pointerInput
35+
import androidx.compose.ui.text.font.FontWeight
3436
import androidx.compose.ui.text.style.TextAlign
37+
import androidx.compose.ui.unit.Dp
3538
import androidx.compose.ui.unit.dp
3639
import androidx.compose.ui.unit.sp
3740
import top.yukonga.miuix.kmp.theme.MiuixTheme
@@ -76,7 +79,7 @@ fun NavigationBar(
7679
.background(Color.Transparent)
7780
) {
7881
HorizontalDivider(
79-
thickness = 0.25.dp,
82+
thickness = 0.75.dp,
8083
color = MiuixTheme.colorScheme.dividerLine
8184
)
8285
Row(
@@ -100,10 +103,12 @@ fun NavigationBar(
100103
else -> MiuixTheme.colorScheme.onSurfaceContainerVariant
101104
}
102105
)
106+
val fontWeight = if (isSelected) FontWeight.Medium else FontWeight.Normal
103107
Column(
104108
horizontalAlignment = Alignment.CenterHorizontally,
105109
modifier = Modifier
106110
.weight(1f / items.size)
111+
.height(NavigationBarHeight)
107112
.pointerInput(Unit) {
108113
detectTapGestures(
109114
onPress = {
@@ -122,11 +127,12 @@ fun NavigationBar(
122127
colorFilter = ColorFilter.tint(tint)
123128
)
124129
Text(
125-
modifier = Modifier.padding(bottom = 14.dp),
130+
modifier = Modifier.padding(bottom = 12.dp),
126131
text = item.label,
127132
color = tint,
128133
textAlign = TextAlign.Center,
129-
fontSize = 13.sp,
134+
fontSize = 12.sp,
135+
fontWeight = fontWeight
130136
)
131137
}
132138
}
@@ -135,6 +141,10 @@ fun NavigationBar(
135141
}
136142
}
137143

144+
/** The default expanded height of a [NavigationBar]. */
145+
val NavigationBarHeight: Dp = 64.dp
146+
147+
138148
/**
139149
* The data class for [NavigationBar].
140150
*

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ fun Switch(
6565
var dragOffset by remember { mutableStateOf(0f) }
6666
val thumbOffset by animateDpAsState(
6767
targetValue = if (isChecked) {
68-
if (isPressed) 26.5.dp else 28.dp
68+
if (!enabled) 28.dp else if (isPressed) 26.5.dp else 28.dp
6969
} else {
70-
if (isPressed) 2.5.dp else 4.dp
70+
if (!enabled) 4.dp else if (isPressed) 2.5.dp else 4.dp
7171
} + dragOffset.dp,
7272
animationSpec = springSpec
7373
)
7474

7575
val thumbSize by animateDpAsState(
76-
targetValue = if (isPressed) 23.dp else 20.dp,
76+
targetValue = if (!enabled) 20.dp else if (isPressed) 23.dp else 20.dp,
7777
animationSpec = springSpec
7878
)
7979

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private fun TopAppBarLayout(
546546
},
547547
modifier = Modifier
548548
.windowInsetsPadding(WindowInsets.statusBars)
549-
.heightIn(max = 60.dp + TopAppBarExpandedHeight)
549+
.heightIn(max = 56.dp + TopAppBarExpandedHeight)
550550
.clipToBounds()
551551
) { measurables, constraints ->
552552
val navigationIconPlaceable =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ fun SuperDropdown(
235235
options = items,
236236
isSelected = items[selectedIndex] == option,
237237
onSelectedIndexChange = {
238+
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
238239
onSelectedIndexChange(it)
239240
dismissPopup()
240241
isDropdownExpanded.value = false

0 commit comments

Comments
 (0)