UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

106 lines (105 loc) 5.57 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { BaseNavigationContainer, getActionFromState, getPathFromState, getStateFromPath, ThemeProvider, validatePathConfig } from "@react-navigation/core"; import { DefaultTheme, LinkingContext, LocaleDirContext, UNSTABLE_UnhandledLinkingContext as UnhandledLinkingContext } from "@react-navigation/native"; import * as React from "react"; import { I18nManager } from "react-native"; import useLatestCallback from "use-latest-callback"; import { useBackButton } from "./useBackButton.native.js"; import { useDocumentTitle } from "./useDocumentTitle.native.js"; import { useLinking } from "./useLinking.native.js"; import { useThenable } from "./useThenable.native.js"; globalThis.REACT_NAVIGATION_DEVTOOLS = /* @__PURE__ */new WeakMap(); function NavigationContainerInner(param, ref) { var { direction = I18nManager.getConstants().isRTL ? "rtl" : "ltr", theme = DefaultTheme, linking, fallback = null, documentTitle, onReady, onStateChange, ...rest } = param, isLinkingEnabled = linking ? linking.enabled !== !1 : !1; linking?.config && validatePathConfig(linking.config); var refContainer = React.useRef(null); useBackButton(refContainer), useDocumentTitle(refContainer, documentTitle); var [lastUnhandledLink, setLastUnhandledLink] = React.useState(), { getInitialState } = useLinking(refContainer, { enabled: isLinkingEnabled, prefixes: [], ...linking }, setLastUnhandledLink), linkingContext = React.useMemo(function () { return { options: linking }; }, [linking]), unhandledLinkingContext = React.useMemo(function () { return { lastUnhandledLink, setLastUnhandledLink }; }, [lastUnhandledLink, setLastUnhandledLink]), onReadyForLinkingHandling = useLatestCallback(function () { var _refContainer_current_getCurrentRoute, _refContainer_current, path = (_refContainer_current = refContainer.current) === null || _refContainer_current === void 0 || (_refContainer_current_getCurrentRoute = _refContainer_current.getCurrentRoute()) === null || _refContainer_current_getCurrentRoute === void 0 ? void 0 : _refContainer_current_getCurrentRoute.path; setLastUnhandledLink(function (previousLastUnhandledLink) { if (previousLastUnhandledLink !== path) return previousLastUnhandledLink; }), onReady?.(); }), onStateChangeForLinkingHandling = useLatestCallback(function (state) { var _refContainer_current_getCurrentRoute, _refContainer_current, path = (_refContainer_current = refContainer.current) === null || _refContainer_current === void 0 || (_refContainer_current_getCurrentRoute = _refContainer_current.getCurrentRoute()) === null || _refContainer_current_getCurrentRoute === void 0 ? void 0 : _refContainer_current_getCurrentRoute.path; setLastUnhandledLink(function (previousLastUnhandledLink) { if (previousLastUnhandledLink !== path) return previousLastUnhandledLink; }), onStateChange?.(state); }); React.useEffect(function () { refContainer.current && REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, { get linking() { var _linking_prefixes, _linking_getStateFromPath, _linking_getPathFromState, _linking_getActionFromState; return { ...linking, enabled: isLinkingEnabled, prefixes: (_linking_prefixes = linking?.prefixes) !== null && _linking_prefixes !== void 0 ? _linking_prefixes : [], getStateFromPath: (_linking_getStateFromPath = linking?.getStateFromPath) !== null && _linking_getStateFromPath !== void 0 ? _linking_getStateFromPath : getStateFromPath, getPathFromState: (_linking_getPathFromState = linking?.getPathFromState) !== null && _linking_getPathFromState !== void 0 ? _linking_getPathFromState : getPathFromState, getActionFromState: (_linking_getActionFromState = linking?.getActionFromState) !== null && _linking_getActionFromState !== void 0 ? _linking_getActionFromState : getActionFromState }; } }); }); var [isResolved, initialState] = useThenable(getInitialState); 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; return isLinkingReady ? /* @__PURE__ */_jsx(LocaleDirContext.Provider, { value: direction, children: /* @__PURE__ */_jsx(UnhandledLinkingContext.Provider, { value: unhandledLinkingContext, children: /* @__PURE__ */_jsx(LinkingContext.Provider, { value: linkingContext, children: /* @__PURE__ */_jsx(BaseNavigationContainer, { ...rest, theme, onReady: onReadyForLinkingHandling, onStateChange: onStateChangeForLinkingHandling, initialState: rest.initialState == null ? initialState : rest.initialState, ref: refContainer }) }) }) }) : /* @__PURE__ */_jsx(ThemeProvider, { value: theme, children: fallback }); } var NavigationContainer = /* @__PURE__ */React.forwardRef(NavigationContainerInner); export { NavigationContainer }; //# sourceMappingURL=NavigationContainer.native.js.map