UNPKG

one

Version:

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

88 lines (85 loc) • 4.03 kB
import { jsx } from "react/jsx-runtime"; import { BaseNavigationContainer, ThemeProvider, getActionFromState, getPathFromState, getStateFromPath, validatePathConfig } from "@react-navigation/core"; import { LinkingContext, LocaleDirContext } from "@react-navigation/native"; import * as React from "react"; import { getLocaleDirection } from "./localeDirection.native.js"; import { DefaultTheme } from "./theme.native.js"; import { useBackButton } from "./useBackButton.native.js"; import { useDocumentTitle } from "./useDocumentTitle.native.js"; import { useLinking } from "./useLinking.native.js"; import { useThenable } from "./useThenable.native.js"; var _globalThis; var _REACT_NAVIGATION_DEVTOOLS; (_REACT_NAVIGATION_DEVTOOLS = (_globalThis = globalThis).REACT_NAVIGATION_DEVTOOLS) !== null && _REACT_NAVIGATION_DEVTOOLS !== void 0 ? _REACT_NAVIGATION_DEVTOOLS : _globalThis.REACT_NAVIGATION_DEVTOOLS = /* @__PURE__ */ new WeakMap(); function NavigationContainerInner(param, ref) { var { direction = getLocaleDirection(), theme = DefaultTheme, linking, fallback = null, documentTitle, onStateChange, ...rest } = param; var isLinkingEnabled = linking ? linking.enabled !== false : false; if (linking === null || linking === void 0 ? void 0 : linking.config) { validatePathConfig(linking.config); } var refContainer = React.useRef(null); useBackButton(refContainer); useDocumentTitle(refContainer, documentTitle); var { getInitialState } = useLinking(refContainer, { enabled: isLinkingEnabled, prefixes: [], ...linking }); var linkingContext = React.useMemo(function() { var _ref, _ref1, _ref2, _ref3; return { options: { ...linking, enabled: isLinkingEnabled, prefixes: (_ref = linking === null || linking === void 0 ? void 0 : linking.prefixes) !== null && _ref !== void 0 ? _ref : [], getStateFromPath: (_ref1 = linking === null || linking === void 0 ? void 0 : linking.getStateFromPath) !== null && _ref1 !== void 0 ? _ref1 : getStateFromPath, getPathFromState: (_ref2 = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _ref2 !== void 0 ? _ref2 : getPathFromState, getActionFromState: (_ref3 = linking === null || linking === void 0 ? void 0 : linking.getActionFromState) !== null && _ref3 !== void 0 ? _ref3 : getActionFromState } }; }, [linking, isLinkingEnabled]); React.useEffect(function() { if (refContainer.current) { var _ref; var previous = REACT_NAVIGATION_DEVTOOLS.get(refContainer.current); var listeners = (_ref = previous === null || previous === void 0 ? void 0 : previous.listeners) !== null && _ref !== void 0 ? _ref : /* @__PURE__ */ new Set(); REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, { get linking() { return linkingContext.options; }, get listeners() { return listeners; } }); } }); var [isResolved, initialState] = useThenable(getInitialState); if (process.env.ONE_DEBUG_ROUTER) { console.info(`[one] \u{1F3E0} NavigationContainer isResolved=${isResolved} initialState=`, JSON.stringify(initialState, null, 2)); console.info(`[one] \u{1F3E0} NavigationContainer rest.initialState=`, rest.initialState); } React.useImperativeHandle(ref, function() { return refContainer.current; }); var isLinkingReady = rest.initialState != null || !isLinkingEnabled || isResolved; if (!isLinkingReady) { return /* @__PURE__ */ jsx(ThemeProvider, { value: theme, children: fallback }); } return /* @__PURE__ */ jsx(LocaleDirContext.Provider, { value: direction, children: /* @__PURE__ */ jsx(LinkingContext.Provider, { value: linkingContext, children: /* @__PURE__ */ jsx(BaseNavigationContainer, { ...rest, theme, onStateChange, initialState: rest.initialState == null ? initialState : rest.initialState, ref: refContainer }) }) }); } var NavigationContainer = /* @__PURE__ */ React.forwardRef(NavigationContainerInner); export { NavigationContainer }; //# sourceMappingURL=NavigationContainer.native.js.map