to_the_cosmic_end
8 months agoProtege
How to send haptic feedback on UI hover/tap in Jetpack compose?
Hi, I am looking for a way to send small vibration as a haptic feedback on my 2D panel app whenever user hovers their raycast over a UI element, and stronger vibration when they tap on that element.
In unity, we can do something like:
XRBaseControllerInteractor.SendHapticImpulse(0.2f, 0.1f);
how to achieve similar effect in Jetpack?
val hapticFeedback = LocalHapticFeedback.current
Button(onClick = {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
//nothing happens
}) {
Text("pick a file")
}
Hi! You can do this with the SpatialInterface.applyHapticFeedback() function.
// inside your AppSystemActivity somewhere // "spatial" is a SpatialInterface inherited from VrActivity // you can pass it around to somewhere else you need it reference it spatial.applyHapticFeedback( // hand: Apply haptics to the specified controller hand. Hand.RIGHT, // amplitude: Value between 0 - 1 for strength of haptics. 0.3f, // duration: Time in nanoseconds for how long the haptic feedback should be applied. (0.03 * 1e9).toLong(), // frequency`: Frequency of vibration (in hz). 128f )
Hopefully this should help!