UNPKG

react-native-haptic-feedback

Version:
39 lines (38 loc) 1.24 kB
"use strict"; import { useCallback } from "react"; import { Pressable } from "react-native"; import RNHapticFeedback from "../hapticFeedback"; import { HapticFeedbackTypes } from "../types"; import { jsx as _jsx } from "react/jsx-runtime"; export function TouchableHaptic({ hapticType = HapticFeedbackTypes.impactMedium, hapticTrigger = "onPressIn", hapticOptions, onPressIn, onPress, onLongPress, ...rest }) { const fireHaptic = useCallback(() => { RNHapticFeedback.trigger(hapticType, hapticOptions); }, [hapticType, hapticOptions]); const handlePressIn = useCallback(e => { if (hapticTrigger === "onPressIn") fireHaptic(); onPressIn?.(e); }, [hapticTrigger, fireHaptic, onPressIn]); const handlePress = useCallback(e => { if (hapticTrigger === "onPress") fireHaptic(); onPress?.(e); }, [hapticTrigger, fireHaptic, onPress]); const handleLongPress = useCallback(e => { if (hapticTrigger === "onLongPress") fireHaptic(); onLongPress?.(e); }, [hapticTrigger, fireHaptic, onLongPress]); return /*#__PURE__*/_jsx(Pressable, { onPressIn: handlePressIn, onPress: handlePress, onLongPress: handleLongPress, ...rest }); } //# sourceMappingURL=TouchableHaptic.js.map