source: imaps-frontend/node_modules/react-use/esm/useVibrate.js

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.0 KB
Line 
1import { useEffect } from 'react';
2import { isNavigator, noop } from './misc/util';
3var isVibrationApiSupported = isNavigator && 'vibrate' in navigator;
4function useVibrate(enabled, pattern, loop) {
5 if (enabled === void 0) { enabled = true; }
6 if (pattern === void 0) { pattern = [1000, 1000]; }
7 if (loop === void 0) { loop = true; }
8 useEffect(function () {
9 var interval;
10 if (enabled) {
11 navigator.vibrate(pattern);
12 if (loop) {
13 var duration = pattern instanceof Array ? pattern.reduce(function (a, b) { return a + b; }) : pattern;
14 interval = setInterval(function () {
15 navigator.vibrate(pattern);
16 }, duration);
17 }
18 }
19 return function () {
20 if (enabled) {
21 navigator.vibrate(0);
22 if (loop) {
23 clearInterval(interval);
24 }
25 }
26 };
27 }, [enabled]);
28}
29export default isVibrationApiSupported ? useVibrate : noop;
Note: See TracBrowser for help on using the repository browser.