UNPKG

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

Version:
83 lines (80 loc) 4.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BottomSheetToolboxInternalProvider = BottomSheetToolboxInternalProvider; exports.useBottomSheetToolboxInternalContext = useBottomSheetToolboxInternalContext; var _nonSecure = require("nanoid/non-secure"); var React = _interopRequireWildcard(require("react")); var _reactNativeReanimated = require("react-native-reanimated"); 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); } /** * The context that describes the current position and state of the bottom-sheet. * * Note: you probably shouldn't write to any of these values directly, instead * refer to the appropriate hook counterparts. */ const BottomSheetToolboxInternalContext = /*#__PURE__*/React.createContext(undefined); /** * Retrieve the bottom sheet internal context, and throw if unavailable. */ function useBottomSheetToolboxInternalContext() { const context = React.useContext(BottomSheetToolboxInternalContext); if (!context) { throw new Error("BottomSheetToolboxInternalProvider not found."); } return context; } /** * Provides a new context for managing the position state of a bottom-sheet. */ function NewBottomSheetToolboxInternalProvider({ children, debugId = null }) { const [defaultDebugId] = React.useState(() => (0, _nonSecure.nanoid)()); const internalDebugId = debugId === null ? defaultDebugId : debugId; const currentPositionSharedValue = (0, _reactNativeReanimated.useSharedValue)(0); const currentPositionDestinationSharedValue = (0, _reactNativeReanimated.useSharedValue)(0); const currentPositionLastVelocitySharedValue = (0, _reactNativeReanimated.useSharedValue)(0); const currentPositionLockSharedValue = (0, _reactNativeReanimated.useSharedValue)(null); const normalizedSnapPointsSharedValue = (0, _reactNativeReanimated.useSharedValue)(null); const wrapperHeightSharedValue = (0, _reactNativeReanimated.useSharedValue)(null); const childrenHeightSharedValue = (0, _reactNativeReanimated.useSharedValue)(null); const footerHeightSharedValue = (0, _reactNativeReanimated.useSharedValue)(null); const isReadySharedValue = (0, _reactNativeReanimated.useSharedValue)(false); const contextValue = React.useMemo(() => ({ currentPositionSharedValue, currentPositionDestinationSharedValue, currentPositionLastVelocitySharedValue, currentPositionLockSharedValue, normalizedSnapPointsSharedValue, wrapperHeightSharedValue, childrenHeightSharedValue, footerHeightSharedValue, isReadySharedValue, debugId: internalDebugId }), [internalDebugId]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(BottomSheetToolboxInternalContext.Provider, { value: contextValue, children: children }); } /** * Provides a context for managing the position state of a bottom-sheet. * By default, this provider will do nothing if a context is already provided. * * If you wish to reset the context, you can pass the 'reset' prop. * This is useful when nesting bottom-sheets. */ function BottomSheetToolboxInternalProvider({ children, reset = false }) { const inheritedContext = React.useContext(BottomSheetToolboxInternalContext); return inheritedContext !== undefined && !reset ? children : /*#__PURE__*/(0, _jsxRuntime.jsx)(NewBottomSheetToolboxInternalProvider, { children: children }); } //# sourceMappingURL=bottom-sheet-toolbox-internal-context.js.map