nowinandroid icon indicating copy to clipboard operation
nowinandroid copied to clipboard

Add HapticFeedback in IconButton

Open kosenda opened this issue 10 months ago • 3 comments

What I have done and why

I thought it would be better to have haptics feedback to make it more obvious that the button was tapped, so I added haptics feedback to the commonly used IconButton

ref Android Developers - Compose UI - 1.8.0-alpha06

LocalHapticFeedback now provides a default HapticFeedback implementation when the Vibrator API indicates that haptics are supported. The following have been added to the HapticFeedbackType - Confirm, ContextClick, GestureEnd, GestureThresholdActivate, Reject, SegmentFrequentTick, SegmentTick, ToggleOn, ToggleOff, VirtualKey. Wear Compose long-clickable components such as Button, IconButton, TextButton, and Card now perform the LONG_PRESS haptic when a long-click handler has been supplied. (I5083d)

Android Developers - HapticFeedbackType

Confirm A haptic effect to signal the confirmation or successful completion of a user interaction..

Android Developers - Tap and press # long-press-show

What I have tried I thought that HapticFeedbackType had ToggleOn and ToggleOff, which seemed to be better, but on my device Pixel 6(Android 15), I didn't get any haptic feedback. So I thought Confirm was appropriate.

    haptics.performHapticFeedback(
        if (isChecked) HapticFeedbackType.ToggleOn else HapticFeedbackType.ToggleOff
    )
    onCheckedChange(isChecked)
},

kosenda avatar Jan 13 '25 04:01 kosenda