UNPKG

one

Version:

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

99 lines (98 loc) 4.08 kB
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-web"; import useLatestCallback from "use-latest-callback"; import { useBackButton } from "./useBackButton"; import { useDocumentTitle } from "./useDocumentTitle"; import { useLinking } from "./useLinking"; import { useThenable } from "./useThenable"; import { jsx } from "react/jsx-runtime"; globalThis.REACT_NAVIGATION_DEVTOOLS = /* @__PURE__ */ new WeakMap(); function NavigationContainerInner({ direction = I18nManager.getConstants().isRTL ? "rtl" : "ltr", theme = DefaultTheme, linking, fallback = null, documentTitle, onReady, onStateChange, ...rest }, ref) { const isLinkingEnabled = linking ? linking.enabled !== !1 : !1; linking?.config && validatePathConfig(linking.config); const refContainer = React.useRef(null); useBackButton(refContainer), useDocumentTitle(refContainer, documentTitle); const [lastUnhandledLink, setLastUnhandledLink] = React.useState(), { getInitialState } = useLinking( refContainer, { enabled: isLinkingEnabled, prefixes: [], ...linking }, setLastUnhandledLink ), linkingContext = React.useMemo(() => ({ options: linking }), [linking]), unhandledLinkingContext = React.useMemo( () => ({ lastUnhandledLink, setLastUnhandledLink }), [lastUnhandledLink, setLastUnhandledLink] ), onReadyForLinkingHandling = useLatestCallback(() => { const path = refContainer.current?.getCurrentRoute()?.path; setLastUnhandledLink((previousLastUnhandledLink) => { if (previousLastUnhandledLink !== path) return previousLastUnhandledLink; }), onReady?.(); }), onStateChangeForLinkingHandling = useLatestCallback( (state) => { const path = refContainer.current?.getCurrentRoute()?.path; setLastUnhandledLink((previousLastUnhandledLink) => { if (previousLastUnhandledLink !== path) return previousLastUnhandledLink; }), onStateChange?.(state); } ); React.useEffect(() => { refContainer.current && REACT_NAVIGATION_DEVTOOLS.set(refContainer.current, { get linking() { return { ...linking, enabled: isLinkingEnabled, prefixes: linking?.prefixes ?? [], getStateFromPath: linking?.getStateFromPath ?? getStateFromPath, getPathFromState: linking?.getPathFromState ?? getPathFromState, getActionFromState: linking?.getActionFromState ?? getActionFromState }; } }); }); const [isResolved, initialState] = useThenable(getInitialState); return 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, () => refContainer.current), rest.initialState != null || !isLinkingEnabled || isResolved ? /* @__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 }); } const NavigationContainer = React.forwardRef(NavigationContainerInner); export { NavigationContainer }; //# sourceMappingURL=NavigationContainer.js.map