UNPKG

2.42 kBJavaScriptView Raw
1import { __assign, __awaiter, __generator, __rest } from "tslib";
2// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3// SPDX-License-Identifier: Apache-2.0
4import { ConsoleLogger as Logger } from '@aws-amplify/core';
5var logger = new Logger('urlListener');
6var handler;
7export default (function (callback) { return __awaiter(void 0, void 0, void 0, function () {
8 var Linking, AppState, subscription;
9 var _a;
10 var _b;
11 return __generator(this, function (_c) {
12 if (handler) {
13 return [2 /*return*/];
14 }
15 try {
16 (_a = require('react-native'), Linking = _a.Linking, AppState = _a.AppState);
17 }
18 catch (error) {
19 /* Keep webpack happy */
20 }
21 handler =
22 handler ||
23 (function (_a) {
24 var url = _a.url, rest = __rest(_a, ["url"]);
25 logger.debug('urlListener', __assign({ url: url }, rest));
26 callback({ url: url });
27 });
28 // Handles backward compatibility. removeEventListener is only available on RN versions before 0.65.
29 if (Linking.removeEventListener === typeof 'function') {
30 Linking.removeEventListener('url', handler);
31 Linking.addEventListener('url', handler);
32 }
33 else {
34 // remove() method is only available on RN v0.65+.
35 (_b = subscription === null || subscription === void 0 ? void 0 : subscription.remove) === null || _b === void 0 ? void 0 : _b.call(subscription);
36 subscription = Linking.addEventListener('url', handler);
37 }
38 AppState.addEventListener('change', function (newAppState) { return __awaiter(void 0, void 0, void 0, function () {
39 var initialUrl;
40 return __generator(this, function (_a) {
41 switch (_a.label) {
42 case 0:
43 if (!(newAppState === 'active')) return [3 /*break*/, 2];
44 return [4 /*yield*/, Linking.getInitialURL()];
45 case 1:
46 initialUrl = _a.sent();
47 handler({ url: initialUrl });
48 _a.label = 2;
49 case 2: return [2 /*return*/];
50 }
51 });
52 }); });
53 return [2 /*return*/];
54 });
55}); });
56//# sourceMappingURL=urlListener.native.js.map
\No newline at end of file