UNPKG

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

Version:
77 lines (74 loc) 2.86 kB
"use strict"; import { nanoid } from "nanoid/non-secure"; import * as React from "react"; import { useSharedValue } from "react-native-reanimated"; /** * 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. */ import { jsx as _jsx } from "react/jsx-runtime"; const BottomSheetToolboxInternalContext = /*#__PURE__*/React.createContext(undefined); /** * Retrieve the bottom sheet internal context, and throw if unavailable. */ export 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(() => nanoid()); const internalDebugId = debugId === null ? defaultDebugId : debugId; const currentPositionSharedValue = useSharedValue(0); const currentPositionDestinationSharedValue = useSharedValue(0); const currentPositionLastVelocitySharedValue = useSharedValue(0); const currentPositionLockSharedValue = useSharedValue(null); const normalizedSnapPointsSharedValue = useSharedValue(null); const wrapperHeightSharedValue = useSharedValue(null); const childrenHeightSharedValue = useSharedValue(null); const footerHeightSharedValue = useSharedValue(null); const isReadySharedValue = useSharedValue(false); const contextValue = React.useMemo(() => ({ currentPositionSharedValue, currentPositionDestinationSharedValue, currentPositionLastVelocitySharedValue, currentPositionLockSharedValue, normalizedSnapPointsSharedValue, wrapperHeightSharedValue, childrenHeightSharedValue, footerHeightSharedValue, isReadySharedValue, debugId: internalDebugId }), [internalDebugId]); return /*#__PURE__*/_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. */ export function BottomSheetToolboxInternalProvider({ children, reset = false }) { const inheritedContext = React.useContext(BottomSheetToolboxInternalContext); return inheritedContext !== undefined && !reset ? children : /*#__PURE__*/_jsx(NewBottomSheetToolboxInternalProvider, { children: children }); } //# sourceMappingURL=bottom-sheet-toolbox-internal-context.js.map