UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

52 lines (48 loc) • 1.65 kB
"use client"; import { createContext, createElement, useContext, useMemo } from "react"; import { getPathFromState } from "../fork/getPathFromState.native.js"; import { getResolvedLinking } from "../router/linkingConfig.native.js"; var StackContext = createContext(null); function StackStateProvider(param) { var { state, descriptors, children } = param; var linking = getResolvedLinking(); var value = useMemo(function() { var screens = state.routes.map(function(route, index) { var _ref, _route_params; var descriptor = descriptors[route.key]; var options = descriptor.options; var href = ((_ref = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _ref !== void 0 ? _ref : getPathFromState)({ ...state, index }, linking === null || linking === void 0 ? void 0 : linking.config); return { key: route.key, name: route.name, params: (_route_params = route.params) !== null && _route_params !== void 0 ? _route_params : {}, href, isFocused: index === state.index, keepMounted: options.keepMounted === true, options, element: descriptor.render() }; }); return { screens, focused: screens[state.index] }; }, [ descriptors, linking, state ]); return createElement(StackContext.Provider, { value }, children); } function useStack() { var value = useContext(StackContext); if (!value) { throw new Error("useStack() must be called inside a <Stack>. it is web-only: on native the stack is rendered by react-navigation."); } return value; } export { StackStateProvider, useStack }; //# sourceMappingURL=useStack.native.js.map