Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch react-native vibration module (#340)
- Loading branch information
1 parent
fb180ef
commit b5717c0
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { |