Skip to content

Commit

Permalink
Make RCTVibration TurboModule-compatible
Browse files Browse the repository at this point in the history
Summary: Making RCTVibration TurboModule-compatible.

Reviewed By: PeteTheHeat

Differential Revision: D17581373

fbshipit-source-id: a7aa2d12e7251d332c855435c2f0d83d87f0d2ac
  • Loading branch information
RSNara authored and facebook-github-bot committed Oct 1, 2019
1 parent 1d7de28 commit 789e9fb
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ namespace facebook {
} // namespace facebook
@protocol NativeVibrationSpec <RCTBridgeModule, RCTTurboModule>

- (void)vibrate:(double)pattern;
- (void)vibrate:(NSNumber *)pattern;
- (void)vibrateByPattern:(NSArray *)pattern
repeat:(double)repeat;
- (void)cancel;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Vibration/NativeVibration.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as TurboModuleRegistry from '../TurboModule/TurboModuleRegistry';

export interface Spec extends TurboModule {
+getConstants: () => {||};
+vibrate: (pattern?: number) => void;
+vibrate: (pattern?: ?number) => void;

// Android only
+vibrateByPattern: (pattern: Array<number>, repeat: number) => void;
Expand Down
21 changes: 0 additions & 21 deletions Libraries/Vibration/RCTVibration.m

This file was deleted.

55 changes: 55 additions & 0 deletions Libraries/Vibration/RCTVibration.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTVibration.h>

#import <AudioToolbox/AudioToolbox.h>
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTLog.h>

#import "RCTVibrationPlugins.h"

@interface RCTVibration() <NativeVibrationSpec>
@end

@implementation RCTVibration

RCT_EXPORT_MODULE()

- (void)vibrate
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

RCT_EXPORT_METHOD(vibrate:(NSNumber *)pattern)
{
[self vibrate];
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:
(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return std::make_shared<facebook::react::NativeVibrationSpecJSI>(self, jsInvoker);
}

RCT_EXPORT_METHOD(vibrateByPattern:(NSArray *)pattern
repeat:(double)repeat)
{
RCTLogError(@"Vibration.vibrateByPattern does not have an iOS implementation");
}

RCT_EXPORT_METHOD(cancel)
{
RCTLogError(@"Vibration.cancel does not have an iOS implementation");
}

@end

Class RCTVibrationCls(void)
{
return RCTVibration.class;
}
40 changes: 40 additions & 0 deletions Libraries/Vibration/RCTVibrationPlugins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by an internal plugin build system
*/

#ifdef RN_DISABLE_OSS_PLUGIN_HEADER

// FB Internal: Plugins.h is autogenerated by the build system.
#import "Plugins.h"

#else

// OSS-compatibility layer

#import <Foundation/Foundation.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"

#ifdef __cplusplus
extern "C" {
#endif

// RCTTurboModuleManagerDelegate should call this to resolve module classes.
Class RCTVibrationClassProvider(const char *name);

// Lookup functions
Class RCTVibrationCls(void);

#ifdef __cplusplus
}
#endif

#pragma GCC diagnostic pop

#endif // RN_DISABLE_OSS_PLUGIN_HEADER
32 changes: 32 additions & 0 deletions Libraries/Vibration/RCTVibrationPlugins.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by an internal plugin build system
*/

#ifndef RN_DISABLE_OSS_PLUGIN_HEADER

// OSS-compatibility layer

#import "RCTVibrationPlugins.h"

#import <string>
#import <unordered_map>

Class RCTVibrationClassProvider(const char *name) {
static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
{"Vibration", RCTVibrationCls},
};

auto p = sCoreModuleClassMap.find(name);
if (p != sCoreModuleClassMap.end()) {
auto classFunc = p->second;
return classFunc();
}
return nil;
}

#endif // RN_DISABLE_OSS_PLUGIN_HEADER
15 changes: 13 additions & 2 deletions Libraries/Vibration/React-RCTVibration.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,30 @@ else
source[:tag] = "v#{version}"
end

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
folly_version = '2018.10.22.00'

Pod::Spec.new do |s|
s.name = "React-RCTVibration"
s.version = version
s.summary = "An API for controlling the vibration hardware of the device."
s.summary = "An API for controlling the vibration hardware of the device."
s.homepage = "http://facebook.github.io/react-native/"
s.documentation_url = "https://facebook.github.io/react-native/docs/vibration"
s.license = package["license"]
s.author = "Facebook, Inc. and its affiliates"
s.platforms = { :ios => "9.0", :tvos => "9.2" }
s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness'
s.source = source
s.source_files = "*.{m}"
s.source_files = "*.{m,mm}"
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
s.header_dir = "RCTVibration"
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
}

s.dependency "Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "React-Core/RCTVibrationHeaders", version
end
4 changes: 3 additions & 1 deletion RNTester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ PODS:
- React-RCTText (1000.0.0):
- React-Core/RCTTextHeaders (= 1000.0.0)
- React-RCTVibration (1000.0.0):
- FBReactNativeSpec (= 1000.0.0)
- Folly (= 2018.10.22.00)
- React-Core/RCTVibrationHeaders (= 1000.0.0)
- ReactCommon/callinvoker (1000.0.0):
- DoubleConversion
Expand Down Expand Up @@ -373,7 +375,7 @@ SPEC CHECKSUMS:
React-RCTSettings: dd4009546ce88c3647c32f0b5922459ab313fdca
React-RCTTest: 73df09ec226fcad6e7e058a313e5dd16cccf86a8
React-RCTText: 9078167d3bc011162326f2d8ef4dd580ec1eca17
React-RCTVibration: 63c20d89204937ff8c7bbc1e712383347e6fbd90
React-RCTVibration: bf05159719598f876ba763e5a58ccbad21e2e82f
ReactCommon: 9d212865526209dc2d01be40340c8d27b53e6bea
Yoga: d88d8b51ee5b247f43211e2edf272438df1b484f

Expand Down

0 comments on commit 789e9fb

Please sign in to comment.