one
Version:
One is a React framework for web, iOS, and Android apps.
117 lines (114 loc) • 5.55 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var NavigationContainer_exports = {};
__export(NavigationContainer_exports, { NavigationContainer: () => NavigationContainer });
module.exports = __toCommonJS(NavigationContainer_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_core = require("@react-navigation/core");
var import_native = require("@react-navigation/native");
var React = __toESM(require("react"), 1);
var import_localeDirection = require("./localeDirection.native.js");
var import_theme = require("./theme.native.js");
var import_useBackButton = require("./useBackButton.native.js");
var import_useDocumentTitle = require("./useDocumentTitle.native.js");
var import_useLinking = require("./useLinking.native.js");
var import_useThenable = require("./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 = (0, import_localeDirection.getLocaleDirection)(), theme = import_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) {
(0, import_core.validatePathConfig)(linking.config);
}
var refContainer = React.useRef(null);
(0, import_useBackButton.useBackButton)(refContainer);
(0, import_useDocumentTitle.useDocumentTitle)(refContainer, documentTitle);
var { getInitialState } = (0, import_useLinking.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 : import_core.getStateFromPath,
getPathFromState: (_ref2 = linking === null || linking === void 0 ? void 0 : linking.getPathFromState) !== null && _ref2 !== void 0 ? _ref2 : import_core.getPathFromState,
getActionFromState: (_ref3 = linking === null || linking === void 0 ? void 0 : linking.getActionFromState) !== null && _ref3 !== void 0 ? _ref3 : import_core.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] = (0, import_useThenable.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__ */ (0, import_jsx_runtime.jsx)(import_core.ThemeProvider, {
value: theme,
children: fallback
});
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_native.LocaleDirContext.Provider, {
value: direction,
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,
onStateChange,
initialState: rest.initialState == null ? initialState : rest.initialState,
ref: refContainer
})
})
});
}
var NavigationContainer = /* @__PURE__ */ React.forwardRef(NavigationContainerInner);
//# sourceMappingURL=NavigationContainer.native.js.map