UNPKG

one

Version:

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

118 lines (116 loc) 4.46 kB
"use strict"; 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( // 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: true }) : target, mod)); var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var linking_native_exports = {}; __export(linking_native_exports, { addEventListener: () => addEventListener, getInitialURL: () => getInitialURL, getPathFromState: () => import_getPathFromState.getPathFromState, getRootURL: () => getRootURL, getStateFromPath: () => import_getStateFromPath.getStateFromPath }); module.exports = __toCommonJS(linking_native_exports); var Linking = __toESM(require("expo-linking"), 1); var import_extractPathFromURL = require("../fork/extractPathFromURL.native.js"); var import_getPathFromState = require("../fork/getPathFromState.native.js"); var import_getStateFromPath = require("../fork/getStateFromPath.native.js"); var _globalThis_expo_modules; var _globalThis_expo; var isExpoGo = typeof expo !== "undefined" && ((_globalThis_expo = globalThis.expo) === null || _globalThis_expo === void 0 ? void 0 : (_globalThis_expo_modules = _globalThis_expo.modules) === null || _globalThis_expo_modules === void 0 ? void 0 : _globalThis_expo_modules.ExpoGo); function getInitialURL() { if (process.env.NODE_ENV === "test") { var _Linking_getInitialURL; return (_Linking_getInitialURL = Linking.getInitialURL()) !== null && _Linking_getInitialURL !== void 0 ? _Linking_getInitialURL : getRootURL(); } return Promise.race([async function () { var url = await Linking.getInitialURL(); if (url && isExpoGo) { var parsed = Linking.parse(url); if (parsed.path === null || ["", "/"].includes((0, import_extractPathFromURL.adjustPathname)({ hostname: parsed.hostname, pathname: parsed.path }))) { return getRootURL(); } } return url !== null && url !== void 0 ? url : getRootURL(); }(), new Promise(function (resolve) { return ( // Timeout in 150ms if `getInitialState` doesn't resolve // Workaround for https://github.com/facebook/react-native/issues/25675 setTimeout(function () { return resolve(getRootURL()); }, 150) ); })]); } var _rootURL; function getRootURL() { if (_rootURL === void 0) { _rootURL = Linking.createURL("/"); } return _rootURL; } function addEventListener(listener) { var callback; if (isExpoGo) { callback = function (param) { var { url } = param; var parsed = Linking.parse(url); if (parsed.path === null || ["", "/"].includes((0, import_extractPathFromURL.adjustPathname)({ hostname: parsed.hostname, pathname: parsed.path }))) { listener(getRootURL()); } else { listener(url); } }; } else { callback = function (param) { var { url } = param; return listener(url); }; } var subscription = Linking.addEventListener("url", callback); return function () { var _subscription_remove; subscription === null || subscription === void 0 ? void 0 : (_subscription_remove = subscription.remove) === null || _subscription_remove === void 0 ? void 0 : _subscription_remove.call(subscription); }; } //# sourceMappingURL=linking.native.js.map