Skip to content

Commit 979a2dc

Browse files
committed
fix: Playback Switch's Haptic Feedback (#2639)
Signed-off-by: Pun Butrach <[email protected]>
1 parent baa9122 commit 979a2dc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/src/main/java/app/revanced/manager/ui/component/haptics/HapticSwitch.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.material3.SwitchDefaults
99
import androidx.compose.runtime.Composable
1010
import androidx.compose.runtime.remember
1111
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.platform.LocalView
1213

1314
@Composable
1415
fun HapticSwitch(
@@ -20,16 +21,19 @@ fun HapticSwitch(
2021
colors: SwitchColors = SwitchDefaults.colors(),
2122
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
2223
) {
24+
val view = LocalView.current
2325
Switch(
2426
checked = checked,
2527
onCheckedChange = { newChecked ->
2628
val useNewConstants = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE
27-
when {
29+
val hapticFeedbackType = when {
2830
newChecked && useNewConstants -> HapticFeedbackConstants.TOGGLE_ON
2931
newChecked -> HapticFeedbackConstants.VIRTUAL_KEY
3032
!newChecked && useNewConstants -> HapticFeedbackConstants.TOGGLE_OFF
3133
!newChecked -> HapticFeedbackConstants.CLOCK_TICK
34+
else -> {HapticFeedbackConstants.VIRTUAL_KEY}
3235
}
36+
view.performHapticFeedback(hapticFeedbackType)
3337
onCheckedChange(newChecked)
3438
},
3539
modifier = modifier,

0 commit comments

Comments
 (0)