nowinandroid
nowinandroid copied to clipboard
Add HapticFeedback in IconButton
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
ConfirmA 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)
},