main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var react_1 = require("react");
|
---|
| 4 | var util_1 = require("./misc/util");
|
---|
| 5 | var isVibrationApiSupported = util_1.isNavigator && 'vibrate' in navigator;
|
---|
| 6 | function useVibrate(enabled, pattern, loop) {
|
---|
| 7 | if (enabled === void 0) { enabled = true; }
|
---|
| 8 | if (pattern === void 0) { pattern = [1000, 1000]; }
|
---|
| 9 | if (loop === void 0) { loop = true; }
|
---|
| 10 | react_1.useEffect(function () {
|
---|
| 11 | var interval;
|
---|
| 12 | if (enabled) {
|
---|
| 13 | navigator.vibrate(pattern);
|
---|
| 14 | if (loop) {
|
---|
| 15 | var duration = pattern instanceof Array ? pattern.reduce(function (a, b) { return a + b; }) : pattern;
|
---|
| 16 | interval = setInterval(function () {
|
---|
| 17 | navigator.vibrate(pattern);
|
---|
| 18 | }, duration);
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | return function () {
|
---|
| 22 | if (enabled) {
|
---|
| 23 | navigator.vibrate(0);
|
---|
| 24 | if (loop) {
|
---|
| 25 | clearInterval(interval);
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | };
|
---|
| 29 | }, [enabled]);
|
---|
| 30 | }
|
---|
| 31 | exports.default = isVibrationApiSupported ? useVibrate : util_1.noop;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.