RCTVibration.mm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTVibration.h>
  8. #import <AudioToolbox/AudioToolbox.h>
  9. #import <FBReactNativeSpec/FBReactNativeSpec.h>
  10. #import <React/RCTLog.h>
  11. #import "RCTVibrationPlugins.h"
  12. @interface RCTVibration() <NativeVibrationSpec>
  13. @end
  14. @implementation RCTVibration
  15. RCT_EXPORT_MODULE()
  16. - (void)vibrate
  17. {
  18. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  19. }
  20. RCT_EXPORT_METHOD(vibrate:(double)pattern)
  21. {
  22. [self vibrate];
  23. }
  24. - (std::shared_ptr<facebook::react::TurboModule>)
  25. getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
  26. nativeInvoker:(std::shared_ptr<facebook::react::CallInvoker>)nativeInvoker
  27. perfLogger:(id<RCTTurboModulePerformanceLogger>)perfLogger
  28. {
  29. return std::make_shared<facebook::react::NativeVibrationSpecJSI>(self, jsInvoker, nativeInvoker, perfLogger);
  30. }
  31. RCT_EXPORT_METHOD(vibrateByPattern:(NSArray *)pattern
  32. repeat:(double)repeat)
  33. {
  34. RCTLogError(@"Vibration.vibrateByPattern does not have an iOS implementation");
  35. }
  36. RCT_EXPORT_METHOD(cancel)
  37. {
  38. RCTLogError(@"Vibration.cancel does not have an iOS implementation");
  39. }
  40. @end
  41. Class RCTVibrationCls(void)
  42. {
  43. return RCTVibration.class;
  44. }