Skip to content

Commit 4ccbcd0

Browse files
committed
library: Checkbox: Sync code style from Switch
1 parent 4495a65 commit 4ccbcd0

File tree

1 file changed

+4
-13
lines changed
  • miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic

1 file changed

+4
-13
lines changed

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ import androidx.compose.runtime.Immutable
2727
import androidx.compose.runtime.LaunchedEffect
2828
import androidx.compose.runtime.Stable
2929
import androidx.compose.runtime.getValue
30-
import androidx.compose.runtime.mutableStateOf
3130
import androidx.compose.runtime.remember
3231
import androidx.compose.runtime.rememberUpdatedState
33-
import androidx.compose.runtime.setValue
3432
import androidx.compose.ui.Alignment
3533
import androidx.compose.ui.Modifier
3634
import androidx.compose.ui.draw.clip
@@ -46,7 +44,6 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
4644
import androidx.compose.ui.platform.LocalHapticFeedback
4745
import androidx.compose.ui.semantics.Role
4846
import androidx.compose.ui.unit.dp
49-
import kotlinx.coroutines.delay
5047
import kotlinx.coroutines.launch
5148
import top.yukonga.miuix.kmp.theme.MiuixTheme
5249

@@ -67,8 +64,9 @@ fun Checkbox(
6764
colors: CheckboxColors = CheckboxDefaults.checkboxColors(),
6865
enabled: Boolean = true,
6966
) {
67+
val isChecked by rememberUpdatedState(checked)
7068
val currentOnCheckedChange by rememberUpdatedState(onCheckedChange)
71-
var onCheck by remember { mutableStateOf(false) }
69+
7270
val hapticFeedback = LocalHapticFeedback.current
7371
val interactionSource = remember { MutableInteractionSource() }
7472

@@ -79,21 +77,15 @@ fun Checkbox(
7977
isPressed || isDragged || isHovered
8078
}
8179

82-
LaunchedEffect(onCheck) {
83-
if (onCheck) {
84-
delay(80)
85-
onCheck = false
86-
}
87-
}
8880

8981
val springSpec = spring<Float>(
9082
dampingRatio = Spring.DampingRatioLowBouncy,
91-
stiffness = if (onCheck) Spring.StiffnessHigh else Spring.StiffnessMedium
83+
stiffness = if (isChecked) Spring.StiffnessHigh else Spring.StiffnessMedium
9284
)
9385

9486
val scale by animateFloatAsState(
9587
targetValue = when {
96-
isInteracted || onCheck -> 0.95f
88+
isInteracted || isChecked -> 0.95f
9789
else -> 1f
9890
},
9991
animationSpec = springSpec
@@ -186,7 +178,6 @@ fun Checkbox(
186178
value = checked,
187179
onValueChange = {
188180
currentOnCheckedChange?.invoke(it)
189-
onCheck = true
190181
hapticFeedback.performHapticFeedback(
191182
if (it) HapticFeedbackType.ToggleOn else HapticFeedbackType.ToggleOff
192183
)

0 commit comments

Comments
 (0)