feat(ios): replace AudioServicesPlaySystemSound with CoreHaptics for Vibration API#55556
feat(ios): replace AudioServicesPlaySystemSound with CoreHaptics for Vibration API#55556hryhoriiK97 wants to merge 4 commits intofacebook:mainfrom
Conversation
|
Hi @hryhoriiK97! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary:
The iOS Vibration API used to rely on
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate), which only created a fixed-length vibration - it didn't support custom durations, patterns, or stopping the vibration once started. To work around this, the JavaScript layer used setTimeout to schedule vibrations, but this method wasn't very accurate and couldn't easily be stopped.This PR replaces the iOS implementation with CoreHaptics (
CHHapticEngine), enabling:Vibration.vibrate(1000)now produces a 1-second haptic[pause, vibrate, pause, vibrate, ...]with hardware-level timingCHHapticAdvancedPatternPlayerand stop instantly oncancel()Changelog:
[IOS] [CHANGED] - Replaced
AudioServicesPlaySystemSoundwith CoreHaptics for Vibration API, enabling custom durations, pattern vibration, and native cancellation on iOSTest Plan:
Tested on a physical iPhone using RNTester → APIs → Vibration:
[0, 500, 200, 500]— two distinct 500ms pulses with a 200ms gap