@@ -27,10 +27,8 @@ import androidx.compose.runtime.Immutable
2727import androidx.compose.runtime.LaunchedEffect
2828import androidx.compose.runtime.Stable
2929import androidx.compose.runtime.getValue
30- import androidx.compose.runtime.mutableStateOf
3130import androidx.compose.runtime.remember
3231import androidx.compose.runtime.rememberUpdatedState
33- import androidx.compose.runtime.setValue
3432import androidx.compose.ui.Alignment
3533import androidx.compose.ui.Modifier
3634import androidx.compose.ui.draw.clip
@@ -46,7 +44,6 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
4644import androidx.compose.ui.platform.LocalHapticFeedback
4745import androidx.compose.ui.semantics.Role
4846import androidx.compose.ui.unit.dp
49- import kotlinx.coroutines.delay
5047import kotlinx.coroutines.launch
5148import 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