GT2/Ejectable/node_modules/react-native-web/dist/exports/Linking/index.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-08-16 00:14:59 +00:00
/**
* Copyright (c) Nicolas Gallagher.
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
import invariant from 'fbjs/lib/invariant';
var initialURL = canUseDOM ? window.location.href : '';
var Linking = {
addEventListener: function addEventListener() {},
removeEventListener: function removeEventListener() {},
canOpenURL: function canOpenURL() {
return Promise.resolve(true);
},
getInitialURL: function getInitialURL() {
return Promise.resolve(initialURL);
},
openURL: function openURL(url) {
try {
open(url);
return Promise.resolve();
} catch (e) {
return Promise.reject(e);
}
},
_validateURL: function _validateURL(url) {
invariant(typeof url === 'string', 'Invalid URL: should be a string. Was: ' + url);
invariant(url, 'Invalid URL: cannot be empty');
}
};
var open = function open(url) {
if (canUseDOM) {
window.location = new URL(url, window.location).toString();
}
};
export default Linking;