@alfalab/bridge-to-native 1.4.0-beta.560edfc → 1.4.0-beta.7b254fa
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,10 +6,12 @@ import { type NativeParamsService } from './native-params-service';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class ExternalLinksService {
|
|
8
8
|
private nativeParamsService;
|
|
9
|
+
private navigationByNativeAppInProgress;
|
|
9
10
|
constructor(nativeParamsService: NativeParamsService);
|
|
10
11
|
handleNativeDeeplink(deeplink: string, closeWebviewBeforeCallNativeDeeplinkHandler?: boolean): void;
|
|
11
12
|
getHrefToOpenInBrowser(link: string): string;
|
|
12
13
|
openInBrowser(link: string): void;
|
|
13
14
|
openInNewWebview(link: string, nativeTitle?: string, closeCurrentWebview?: boolean): void;
|
|
14
15
|
openPdf(url: string, type?: PdfType, title?: string): void;
|
|
16
|
+
private navigateByNativeApp;
|
|
15
17
|
}
|
|
@@ -4,6 +4,7 @@ exports.ExternalLinksService = void 0;
|
|
|
4
4
|
const query_and_headers_keys_1 = require("../../query-and-headers-keys");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const CANCEL_NEW_CALLS_TO_NA_TIME = 150;
|
|
7
8
|
const QUERY_OPEN_IN_BROWSER_KEY = 'openInBrowser';
|
|
8
9
|
const QUERY_OPEN_IN_BROWSER_VALUE = 'true';
|
|
9
10
|
/**
|
|
@@ -13,8 +14,12 @@ const QUERY_OPEN_IN_BROWSER_VALUE = 'true';
|
|
|
13
14
|
class ExternalLinksService {
|
|
14
15
|
constructor(nativeParamsService) {
|
|
15
16
|
this.nativeParamsService = nativeParamsService;
|
|
17
|
+
this.navigationByNativeAppInProgress = false;
|
|
16
18
|
}
|
|
17
19
|
handleNativeDeeplink(deeplink, closeWebviewBeforeCallNativeDeeplinkHandler = false) {
|
|
20
|
+
if (this.navigationByNativeAppInProgress) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
18
23
|
const clearedDeeplinkPath = deeplink.replace(constants_1.DEEP_LINK_PATTERN, '');
|
|
19
24
|
const originalNativeUrl = `${this.nativeParamsService.appId}://${clearedDeeplinkPath}`;
|
|
20
25
|
const preparedNativeUrl = this.nativeParamsService.environment === 'ios'
|
|
@@ -28,7 +33,7 @@ class ExternalLinksService {
|
|
|
28
33
|
setTimeout(() => window.location.replace(preparedNativeUrl), 0);
|
|
29
34
|
return;
|
|
30
35
|
}
|
|
31
|
-
|
|
36
|
+
this.navigateByNativeApp(preparedNativeUrl);
|
|
32
37
|
}
|
|
33
38
|
getHrefToOpenInBrowser(link) {
|
|
34
39
|
if (!this.nativeParamsService.canUseNativeFeature('linksInBrowser')) {
|
|
@@ -39,13 +44,16 @@ class ExternalLinksService {
|
|
|
39
44
|
return url.href;
|
|
40
45
|
}
|
|
41
46
|
openInBrowser(link) {
|
|
47
|
+
if (this.navigationByNativeAppInProgress) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
42
50
|
if (!this.nativeParamsService.canUseNativeFeature('linksInBrowser')) {
|
|
43
51
|
this.openInNewWebview(link);
|
|
44
52
|
return;
|
|
45
53
|
}
|
|
46
54
|
const url = new URL(link);
|
|
47
55
|
url.searchParams.append(QUERY_OPEN_IN_BROWSER_KEY, QUERY_OPEN_IN_BROWSER_VALUE);
|
|
48
|
-
|
|
56
|
+
this.navigateByNativeApp(url.href);
|
|
49
57
|
}
|
|
50
58
|
openInNewWebview(link, nativeTitle = '', closeCurrentWebview = false) {
|
|
51
59
|
const url = new URL(link);
|
|
@@ -55,6 +63,9 @@ class ExternalLinksService {
|
|
|
55
63
|
this.handleNativeDeeplink(`/webFeature?type=recommendation&url=${encodeURIComponent(url.toString())}`, closeCurrentWebview);
|
|
56
64
|
}
|
|
57
65
|
openPdf(url, type = 'pdfFile', title) {
|
|
66
|
+
if (this.navigationByNativeAppInProgress) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
58
69
|
let replaceUrl = url;
|
|
59
70
|
if (this.nativeParamsService.environment === 'ios') {
|
|
60
71
|
const params = new URLSearchParams();
|
|
@@ -66,10 +77,18 @@ class ExternalLinksService {
|
|
|
66
77
|
const paramsStr = params.toString();
|
|
67
78
|
replaceUrl = `${this.nativeParamsService.appId}:///dashboard/pdf_viewer?${paramsStr}`;
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
replaceUrl =
|
|
81
|
+
this.nativeParamsService.environment === 'ios'
|
|
82
|
+
? (0, utils_1.appendFromCurrentQueryParamForIos)(replaceUrl)
|
|
83
|
+
: replaceUrl;
|
|
84
|
+
this.navigateByNativeApp(replaceUrl);
|
|
85
|
+
}
|
|
86
|
+
navigateByNativeApp(url) {
|
|
87
|
+
this.navigationByNativeAppInProgress = true;
|
|
88
|
+
window.location.replace(url);
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
this.navigationByNativeAppInProgress = false;
|
|
91
|
+
}, CANCEL_NEW_CALLS_TO_NA_TIME);
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
exports.ExternalLinksService = ExternalLinksService;
|
package/package.json
CHANGED