nativescript-vibrate
Version:
A vibrate NativeScript plugin for Android and iOS
30 lines • 1.07 kB
JavaScript
import { Common } from './vibrate.common';
import { Application } from '@nativescript/core';
export class Vibrate extends Common {
hasVibrator() {
return this.getVibratorService().hasVibrator();
}
vibrate(param = 300, repeat = -1) {
if (this.hasVibrator()) {
if (typeof param === "number") {
this.getVibratorService().vibrate(param);
}
else {
const patternLength = param.length;
let pattern = Array.create('long', patternLength);
param.forEach((value, index) => { pattern[index] = value; });
this.getVibratorService().vibrate(pattern, repeat);
}
}
}
cancel() {
this.getVibratorService().cancel();
}
getVibratorService() {
if (!this.vibratorService) {
this.vibratorService = Application.android.context.getSystemService(android.content.Context.VIBRATOR_SERVICE);
}
return this.vibratorService;
}
}
//# sourceMappingURL=vibrate.android.js.map