UNPKG

react-native-haptic-feedback

Version:
44 lines (43 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TouchableHaptic = TouchableHaptic; var _react = require("react"); var _reactNative = require("react-native"); var _hapticFeedback = _interopRequireDefault(require("../hapticFeedback")); var _types = require("../types"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function TouchableHaptic({ hapticType = _types.HapticFeedbackTypes.impactMedium, hapticTrigger = "onPressIn", hapticOptions, onPressIn, onPress, onLongPress, ...rest }) { const fireHaptic = (0, _react.useCallback)(() => { _hapticFeedback.default.trigger(hapticType, hapticOptions); }, [hapticType, hapticOptions]); const handlePressIn = (0, _react.useCallback)(e => { if (hapticTrigger === "onPressIn") fireHaptic(); onPressIn?.(e); }, [hapticTrigger, fireHaptic, onPressIn]); const handlePress = (0, _react.useCallback)(e => { if (hapticTrigger === "onPress") fireHaptic(); onPress?.(e); }, [hapticTrigger, fireHaptic, onPress]); const handleLongPress = (0, _react.useCallback)(e => { if (hapticTrigger === "onLongPress") fireHaptic(); onLongPress?.(e); }, [hapticTrigger, fireHaptic, onLongPress]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, { onPressIn: handlePressIn, onPress: handlePress, onLongPress: handleLongPress, ...rest }); } //# sourceMappingURL=TouchableHaptic.js.map