UNPKG

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

Version:
101 lines (99 loc) 4.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BottomSheetToolboxComposer = BottomSheetToolboxComposer; var React = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _reactNativeReanimated = require("react-native-reanimated"); var _reactNativeSafeAreaContext = require("react-native-safe-area-context"); var _components = require("./components"); var _bottomSheetToolboxInternalContext = require("./context/bottom-sheet-toolbox-internal-context"); var _hooks = require("./hooks"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function useSetupSnapPoints(snapPoints, disableSnapPointKeyboardAdjust) { const { normalizedSnapPointsSharedValue } = (0, _bottomSheetToolboxInternalContext.useBottomSheetToolboxInternalContext)(); const normalizedSnapPoints = (0, _hooks.useNormalizedSnapPoints)(snapPoints); const keyboardAvoidingSnapPointsSharedValue = (0, _hooks.useKeyboardAvoidingSnapPoints)(normalizedSnapPoints); (0, _reactNativeReanimated.useAnimatedReaction)(() => disableSnapPointKeyboardAdjust ? normalizedSnapPoints.get() : keyboardAvoidingSnapPointsSharedValue.get(), kb => { normalizedSnapPointsSharedValue.set(kb); }, [keyboardAvoidingSnapPointsSharedValue, normalizedSnapPoints, disableSnapPointKeyboardAdjust]); } function useSetupIsReady({ additionalIsReady = true, onReadyChange }) { const { isReadySharedValue } = (0, _bottomSheetToolboxInternalContext.useBottomSheetToolboxInternalContext)(); (0, _hooks.useBottomSheetIsReady)(additionalIsReady); (0, _reactNativeReanimated.useAnimatedReaction)(() => isReadySharedValue.get(), (ready, lastReady) => { if (ready === lastReady) return; if (onReadyChange) (0, _reactNativeReanimated.runOnJS)(onReadyChange)(ready); }, [isReadySharedValue]); } function useInsetTopWithDefault(outerInsetTop) { const insets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)(); const insetTop = outerInsetTop === undefined ? Math.max(insets.top + 12, 24) : outerInsetTop || 0; return insetTop; } /** * A general-purpose composer of all our bottom sheet utilities. */ function BottomSheetToolboxComposer({ children, snapPoints, initialSnapPointIndex, insetTop: outerInsetTop, backdropComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BottomSheetToolboxDefaultBackdrop, {}), overlayComponent, onSnapChange, onClose, sheetStyle, disableSheetDrag = false, disableSnapPointKeyboardAdjust = false, additionalIsReady = true, onReadyChange, ref }) { (0, _hooks.useBottomSheetDevToolsAdapter)(); useSetupSnapPoints(snapPoints, disableSnapPointKeyboardAdjust); useSetupIsReady({ additionalIsReady, ...(onReadyChange && { onReadyChange }) }); const insetTop = useInsetTopWithDefault(outerInsetTop); (0, _hooks.useBottomSheetOpenWhenReady)(initialSnapPointIndex); (0, _hooks.useBottomSheetSnapWhenIdle)(); (0, _hooks.useBottomSheetOnSnapDetection)(onSnapChange); (0, _hooks.useBottomSheetOnCloseDetection)(onClose); const actions = (0, _hooks.useBottomSheetActions)("BottomSheetImperativeHandle"); React.useImperativeHandle(ref, () => actions, [actions]); return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, { children: [backdropComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: _reactNative.StyleSheet.absoluteFill, pointerEvents: "box-none", children: backdropComponent }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.BottomSheetToolboxWrapper, { insetTop: insetTop, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BottomSheetDragGesture, { id: "BottomSheetToolboxComposer:sheet-drag", disabled: disableSheetDrag, children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BottomSheetToolboxSheet, { style: sheetStyle, children: children }) }), overlayComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, { style: _reactNative.StyleSheet.absoluteFill, pointerEvents: "box-none", children: overlayComponent })] })] }); } //# sourceMappingURL=bottom-sheet-toolbox-composer.js.map