How to emit haptic feedback ? #133
-
Hello, I tried many things to emit haptic feedback on android side but without any success :( func feedback() {
#if !SKIP
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
#else
// Need to be inside a @Composable
let view = LocalView.current
view.performHapticFeedback(HapticFeedbackConstantsCompat.KEYBOARD_TAP)
#endif
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Untested, but how about something like this: #if !SKIP
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
#else
let context = ProcessInfo.processInfo.androidContext // Android-specific extension to get the global Context
// https://developer.android.com/reference/android/os/VibratorManager
if let vibratorManager = context.getSystemService(android.content.Context.VIBRATOR_SERVICE) as? android.os.VibratorManager {
// https://developer.android.com/reference/android/os/Vibrator
if let vibrator = vibratorManager.getDefaultVibrator() {
// https://developer.android.com/reference/android/os/VibrationEffect
vibrator.vibrate(android.os.VibrationEffect.createPredefined(android.os.VibrationEffect.EFFECT_CLICK))
}
}
#endif |
Beta Was this translation helpful? Give feedback.
-
This seemed like it would be useful feature, so I've gone ahead and added the API ( Note that you will need to add the Please let us know if you have any questions or problems with the new feature, and thanks for the suggestion! |
Beta Was this translation helpful? Give feedback.
This seemed like it would be useful feature, so I've gone ahead and added the API (
UIImpactFeedbackGenerator
,UINotificationFeedbackGenerator
, andUISelectionFeedbackGenerator
) to skip-ui 0.9.5. Once you update withFile
/Packages
/Update to Latest Package Versions
, you should be able to just use those types to create haptic feedback on the Android side in the same way as the iOS side.Note that you will need to add the
android.permission.VIBRATE
permission to yourAndroidManifest.xml
file. See: https://skip.tools/docs/modules/skip-ui/#hapticsPlease let us know if you have any questions or problems with the new feature, and thanks for the suggestion!