UNPKG

@attio/react-native-bottom-sheet-toolbox

Version:
26 lines (25 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useBottomSheetOnCloseDetection = useBottomSheetOnCloseDetection; var _reactNativeReanimated = require("react-native-reanimated"); var _context = require("../context"); var _utils = require("../utils"); function useBottomSheetOnCloseDetection(onClose) { const { isReadySharedValue, currentPositionSharedValue } = (0, _context.useBottomSheetToolboxInternalContext)(); const hasOpenedSharedValue = (0, _reactNativeReanimated.useSharedValue)(false); (0, _reactNativeReanimated.useAnimatedReaction)(() => currentPositionSharedValue.get(), currentPosition => { if (currentPosition === null || !isReadySharedValue.get()) return; hasOpenedSharedValue.set(hasOpenedSharedValue.get() || currentPosition > _utils.CLOSED_SNAP_POINT); const didClose = hasOpenedSharedValue.get() && currentPosition === _utils.CLOSED_SNAP_POINT; if (didClose) { hasOpenedSharedValue.set(false); if (onClose) (0, _reactNativeReanimated.runOnJS)(onClose)(); } }, [currentPositionSharedValue]); } //# sourceMappingURL=use-bottom-sheet-on-close-detection.js.map