UNPKG

react-native-haptic-feedback

Version:
60 lines (59 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useHaptics = useHaptics; var _react = require("react"); var _hapticFeedback = _interopRequireDefault(require("../hapticFeedback")); var _playHaptic = require("../utils/playHaptic"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * React hook that provides haptic feedback methods with optional default options. * Returns a stable object — methods only change when the option values change. * * @example * const haptics = useHaptics({ enableVibrateFallback: true }); * haptics.trigger('impactMedium'); */ function useHaptics(defaultOptions) { const enableVibrateFallback = defaultOptions?.enableVibrateFallback; const ignoreAndroidSystemSettings = defaultOptions?.ignoreAndroidSystemSettings; return (0, _react.useMemo)(() => ({ trigger(type, opts) { _hapticFeedback.default.trigger(type, { ...defaultOptions, ...opts }); }, triggerPattern(events, opts) { _hapticFeedback.default.triggerPattern(events, { ...defaultOptions, ...opts }); }, stop() { _hapticFeedback.default.stop(); }, isSupported() { return _hapticFeedback.default.isSupported(); }, playHaptic(ahapFile, fallback, opts) { return (0, _playHaptic.playHaptic)(ahapFile, fallback, { ...defaultOptions, ...opts }); }, impact(type, intensity, opts) { _hapticFeedback.default.impact(type, intensity, { ...defaultOptions, ...opts }); }, setEnabled: _hapticFeedback.default.setEnabled, isEnabled: _hapticFeedback.default.isEnabled, getSystemHapticStatus: _hapticFeedback.default.getSystemHapticStatus, /** @platform ios */ playAHAP: _hapticFeedback.default.playAHAP }), [enableVibrateFallback, ignoreAndroidSystemSettings]); } //# sourceMappingURL=useHaptics.js.map