Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch react-native vibration module #340

Merged
merged 1 commit into from Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions patches/react-native+0.62.0-rc.1.patch
@@ -0,0 +1,74 @@
diff --git a/node_modules/react-native/Libraries/Vibration/NativeVibration.js b/node_modules/react-native/Libraries/Vibration/NativeVibration.js
index abdfa68..6de5352 100644
--- a/node_modules/react-native/Libraries/Vibration/NativeVibration.js
+++ b/node_modules/react-native/Libraries/Vibration/NativeVibration.js
@@ -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;
diff --git a/node_modules/react-native/Libraries/Vibration/RCTVibration.mm b/node_modules/react-native/Libraries/Vibration/RCTVibration.mm
index a264246..80925bf 100644
--- a/node_modules/react-native/Libraries/Vibration/RCTVibration.mm
+++ b/node_modules/react-native/Libraries/Vibration/RCTVibration.mm
@@ -25,7 +25,7 @@ - (void)vibrate
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

-RCT_EXPORT_METHOD(vibrate:(NSNumber *)pattern)
+RCT_EXPORT_METHOD(vibrate:(nonnull NSNumber *)pattern)
{
[self vibrate];
}
diff --git a/node_modules/react-native/Libraries/Vibration/Vibration.js b/node_modules/react-native/Libraries/Vibration/Vibration.js
index 2f20cd7..6165258 100644
--- a/node_modules/react-native/Libraries/Vibration/Vibration.js
+++ b/node_modules/react-native/Libraries/Vibration/Vibration.js
@@ -22,6 +22,7 @@ const Platform = require('../Utilities/Platform');

let _vibrating: boolean = false;
let _id: number = 0; // _id is necessary to prevent race condition.
+const _default_vibration_length = 400;

function vibrateByPattern(pattern: Array<number>, repeat: boolean = false) {
if (_vibrating) {
@@ -29,7 +30,7 @@ function vibrateByPattern(pattern: Array<number>, repeat: boolean = false) {
}
_vibrating = true;
if (pattern[0] === 0) {
- NativeVibration.vibrate();
+ NativeVibration.vibrate(_default_vibration_length);
pattern = pattern.slice(1);
}
if (pattern.length === 0) {
@@ -48,7 +49,7 @@ function vibrateScheduler(
if (!_vibrating || id !== _id) {
return;
}
- NativeVibration.vibrate();
+ NativeVibration.vibrate(_default_vibration_length);
if (nextIndex >= pattern.length) {
if (repeat) {
nextIndex = 0;
@@ -70,7 +71,7 @@ const Vibration = {
* See https://facebook.github.io/react-native/docs/vibration.html#vibrate
*/
vibrate: function(
- pattern: number | Array<number> = 400,
+ pattern: number | Array<number> = _default_vibration_length,
repeat: boolean = false,
) {
if (Platform.OS === 'android') {
@@ -86,7 +87,7 @@ const Vibration = {
return;
}
if (typeof pattern === 'number') {
- NativeVibration.vibrate();
+ NativeVibration.vibrate(pattern);
} else if (Array.isArray(pattern)) {
vibrateByPattern(pattern, repeat);
} else {