Skip to content

Commit 7fc806e

Browse files
committed
library: Add Checkbox hapticFeedback
1 parent d78a19f commit 7fc806e

File tree

1 file changed

+7
-1
lines changed
  • miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import androidx.compose.ui.graphics.Path
2626
import androidx.compose.ui.graphics.PathMeasure
2727
import androidx.compose.ui.graphics.drawscope.rotate
2828
import androidx.compose.ui.graphics.vector.PathParser
29+
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
2930
import androidx.compose.ui.input.pointer.pointerInput
31+
import androidx.compose.ui.platform.LocalHapticFeedback
3032
import androidx.compose.ui.semantics.Role
3133
import androidx.compose.ui.unit.dp
3234
import top.yukonga.miuix.kmp.theme.MiuixTheme
@@ -49,6 +51,7 @@ fun Checkbox(
4951
) {
5052
val isChecked by rememberUpdatedState(checked)
5153
var isPressed by remember { mutableStateOf(false) }
54+
val hapticFeedback = LocalHapticFeedback.current
5255
val backgroundColor by animateColorAsState(if (isChecked) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.secondary)
5356
val disabledBackgroundColor by rememberUpdatedState(if (isChecked) MiuixTheme.colorScheme.disabledPrimary else MiuixTheme.colorScheme.disabledSecondary)
5457
val checkboxSize by animateDpAsState(if (!enabled) 22.dp else if (isPressed) 20.dp else 22.dp)
@@ -66,7 +69,10 @@ fun Checkbox(
6669
if (onCheckedChange != null) {
6770
Modifier.toggleable(
6871
value = isChecked,
69-
onValueChange = { onCheckedChange(it) },
72+
onValueChange = {
73+
onCheckedChange(it)
74+
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
75+
},
7076
enabled = enabled,
7177
role = Role.Checkbox,
7278
indication = null,

0 commit comments

Comments
 (0)