one
Version:
One is a new React Framework that makes Vite serve both native and web.
114 lines (113 loc) • 7.19 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var NavigationContainer_exports = {};
__export(NavigationContainer_exports, {
NavigationContainer: () => NavigationContainer
});
module.exports = __toCommonJS(NavigationContainer_exports);
var import_jsx_runtime = require("react/jsx-runtime"), import_core = require("@react-navigation/core"), React = __toESM(require("react"), 1), import_react_native = require("react-native"), import_use_latest_callback = __toESM(require("use-latest-callback"), 1), import_native = require("@react-navigation/native"), import_useBackButton = require("./useBackButton"), import_useDocumentTitle = require("./useDocumentTitle"), import_useLinking = require("./useLinking"), import_useThenable = require("./useThenable");
globalThis.REACT_NAVIGATION_DEVTOOLS = /* @__PURE__ */ new WeakMap();
function NavigationContainerInner(param, ref) {
var { direction = import_react_native.I18nManager.getConstants().isRTL ? "rtl" : "ltr", theme = import_native.DefaultTheme, linking, fallback = null, documentTitle, onReady, onStateChange, ...rest } = param, isLinkingEnabled = linking ? linking.enabled !== !1 : !1;
linking != null && linking.config && (0, import_core.validatePathConfig)(linking.config);
var refContainer = React.useRef(null);
(0, import_useBackButton.useBackButton)(refContainer), (0, import_useDocumentTitle.useDocumentTitle)(refContainer, documentTitle);
var [lastUnhandledLink, setLastUnhandledLink] = React.useState(), { getInitialState } = (0, import_useLinking.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 = (0, import_use_latest_callback.default)(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 == null || onReady();
}), onStateChangeForLinkingHandling = (0, import_use_latest_callback.default)(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 == null || 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 == null ? void 0 : linking.prefixes) !== null && _linking_prefixes !== void 0 ? _linking_prefixes : [],
getStateFromPath: (_linking_getStateFromPath = linking == null ? void 0 : linking.getStateFromPath) !== null && _linking_getStateFromPath !== void 0 ? _linking_getStateFromPath : import_core.getStateFromPath,
getPathFromState: (_linking_getPathFromState = linking == null ? void 0 : linking.getPathFromState) !== null && _linking_getPathFromState !== void 0 ? _linking_getPathFromState : import_core.getPathFromState,
getActionFromState: (_linking_getActionFromState = linking == null ? void 0 : linking.getActionFromState) !== null && _linking_getActionFromState !== void 0 ? _linking_getActionFromState : import_core.getActionFromState
};
}
});
});
var [isResolved, initialState] = (0, import_useThenable.useThenable)(getInitialState);
React.useImperativeHandle(ref, function() {
return refContainer.current;
});
var isLinkingReady = rest.initialState != null || !isLinkingEnabled || isResolved;
return isLinkingReady ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_native.LocaleDirContext.Provider, {
value: direction,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_native.UNSTABLE_UnhandledLinkingContext.Provider, {
value: unhandledLinkingContext,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_native.LinkingContext.Provider, {
value: linkingContext,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.BaseNavigationContainer, {
...rest,
theme,
onReady: onReadyForLinkingHandling,
onStateChange: onStateChangeForLinkingHandling,
initialState: rest.initialState == null ? initialState : rest.initialState,
ref: refContainer
})
})
})
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ThemeProvider, {
value: theme,
children: fallback
});
}
var NavigationContainer = /* @__PURE__ */ React.forwardRef(NavigationContainerInner);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NavigationContainer
});
//# sourceMappingURL=NavigationContainer.js.map