UNPKG

@tamagui/react-native-web-lite

Version:
93 lines (91 loc) 3.75 kB
import { canUseDOM, invariant } from "@tamagui/react-native-web-internals"; function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } function _define_property(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value, enumerable: !0, configurable: !0, writable: !0 }) : obj[key] = value, obj; } var initialURL = canUseDOM ? window.location.href : "", Linking = /* @__PURE__ */function () { "use strict"; function Linking2() { var _this = this; _class_call_check(this, Linking2), _define_property(this, "_eventCallbacks", {}), _define_property(this, "addEventListener", function (event, callback) { if (!_this._eventCallbacks[event]) { _this._eventCallbacks[event] = [callback]; return; } _this._eventCallbacks[event].push(callback); }), _define_property(this, "removeEventListener", function (event, callback) { var callbacks = _this._eventCallbacks[event], filteredCallbacks = callbacks.filter(function (c) { return c.toString() !== callback.toString(); }); _this._eventCallbacks[event] = filteredCallbacks; }); } return _create_class(Linking2, [{ key: "_dispatchEvent", value: function (event) { for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) data[_key - 1] = arguments[_key]; var listeners = this._eventCallbacks[event]; listeners != null && Array.isArray(listeners) && listeners.map(function (listener) { listener(...data); }); } }, { key: "canOpenURL", value: function () { return Promise.resolve(!0); } }, { key: "getInitialURL", value: function () { return Promise.resolve(initialURL); } }, { /** * Try to open the given url in a secure fashion. The method returns a Promise object. * If a target is passed (including undefined) that target will be used, otherwise '_blank'. * If the url opens, the promise is resolved. If not, the promise is rejected. * Dispatches the `onOpen` event if `url` is opened successfully. */ key: "openURL", value: function (url, target) { arguments.length === 1 && (target = "_blank"); try { return open(url, target), this._dispatchEvent("onOpen", url), Promise.resolve(); } catch (e) { return Promise.reject(e); } } }, { key: "_validateURL", value: function (url) { invariant(typeof url == "string", "Invalid URL: should be a string. Was: " + url), invariant(url, "Invalid URL: cannot be empty"); } }]), Linking2; }(), open = function (url, target) { if (canUseDOM) { var urlToOpen = new URL(url, window.location).toString(); urlToOpen.indexOf("tel:") === 0 ? window.location = urlToOpen : window.open(urlToOpen, target, "noopener"); } }, Linking_default = new Linking(); export { Linking_default as default }; //# sourceMappingURL=index.native.js.map