mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Add support for vibration patterns
Summary:and "not supported" warnings for ios Closes https://github.com/facebook/react-native/pull/6400 Differential Revision: D3113988 fb-gh-sync-id: 169623f157ec59c38b4368cbc668c85201b67ed8 fbshipit-source-id: 169623f157ec59c38b4368cbc668c85201b67ed8
This commit is contained in:
committed by
Facebook Github Bot 0
parent
2bcf4bef2b
commit
e20e8a3cc8
@@ -27,11 +27,35 @@ var Platform = require('Platform');
|
||||
*/
|
||||
|
||||
var Vibration = {
|
||||
vibrate: function(duration: number = 400) {
|
||||
vibrate: function(pattern: number | Array<number> = 400, repeat: boolean = false) {
|
||||
if (Platform.OS === 'android') {
|
||||
RCTVibration.vibrate(duration);
|
||||
if (typeof pattern === 'number') {
|
||||
RCTVibration.vibrate(pattern);
|
||||
} else if (Array.isArray(pattern)) {
|
||||
RCTVibration.vibrateByPattern(pattern, repeat ? 0 : -1);
|
||||
} else {
|
||||
throw new Error('Vibration pattern should be a number or array');
|
||||
}
|
||||
} else {
|
||||
RCTVibration.vibrate();
|
||||
if (typeof pattern === 'number') {
|
||||
RCTVibration.vibrate();
|
||||
} else if (Array.isArray(pattern)) {
|
||||
console.warn('Vibration patterns are not supported on iOS');
|
||||
} else {
|
||||
throw new Error('Vibration pattern should be a number or array');
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Stop vibration
|
||||
*
|
||||
* @platform android
|
||||
*/
|
||||
cancel: function() {
|
||||
if (Platform.OS === 'ios') {
|
||||
console.warn('Vibration.cancel is not supported on iOS');
|
||||
} else {
|
||||
RCTVibration.cancel();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user