@alfalab/bridge-to-native 1.3.2-beta.0084dcb → 1.3.2-beta.531b429

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.
@@ -0,0 +1 @@
1
+ export declare const closeWebviewUtil: () => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closeWebviewUtil = void 0;
4
+ const QUERY_CLOSE_WEBVIEW_KEY = 'closeWebView';
5
+ const QUERY_CLOSE_WEBVIEW_VALUE = 'true';
6
+ const closeWebviewUtil = () => {
7
+ const originalPageUrl = new URL(window.location.href);
8
+ originalPageUrl.searchParams.set(QUERY_CLOSE_WEBVIEW_KEY, QUERY_CLOSE_WEBVIEW_VALUE);
9
+ window.location.href = originalPageUrl.toString();
10
+ };
11
+ exports.closeWebviewUtil = closeWebviewUtil;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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
- const utils_1 = require("./utils");
6
+ const close_webview_util_1 = require("./close-webview-util");
7
7
  const QUERY_OPEN_IN_BROWSER_KEY = 'openInBrowser';
8
8
  const QUERY_OPEN_IN_BROWSER_VALUE = 'true';
9
9
  /**
@@ -16,19 +16,15 @@ class ExternalLinksService {
16
16
  }
17
17
  handleNativeDeeplink(deeplink, closeWebviewBeforeCallNativeDeeplinkHandler = false) {
18
18
  const clearedDeeplinkPath = deeplink.replace(constants_1.DEEP_LINK_PATTERN, '');
19
- const nativeUrl = `${this.nativeParamsService.appId}://${clearedDeeplinkPath}`;
20
- const replaceUrl = this.nativeParamsService.environment === 'ios'
21
- ? (0, utils_1.appendFromCurrentQueryParamForIos)(nativeUrl)
22
- : nativeUrl;
23
19
  if (closeWebviewBeforeCallNativeDeeplinkHandler &&
24
20
  this.nativeParamsService.canUseNativeFeature('savedBackStack')) {
25
- (0, utils_1.closeWebviewUtil)();
21
+ (0, close_webview_util_1.closeWebviewUtil)();
26
22
  // Проверено, ОС получает диплинк и передаёт его NA, не смотря на то,
27
23
  // что это происходит в следующей макрозадаче после команды на закрытие WV.
28
- setTimeout(() => window.location.replace(replaceUrl), 0);
24
+ setTimeout(() => window.location.replace(`${this.nativeParamsService.appId}://${clearedDeeplinkPath}`), 0);
29
25
  return;
30
26
  }
31
- window.location.replace(replaceUrl);
27
+ window.location.replace(`${this.nativeParamsService.appId}://${clearedDeeplinkPath}`);
32
28
  }
33
29
  getHrefToOpenInBrowser(link) {
34
30
  if (!this.nativeParamsService.canUseNativeFeature('linksInBrowser')) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.NativeNavigationAndTitleService = void 0;
5
5
  const query_and_headers_keys_1 = require("../../query-and-headers-keys");
6
- const utils_1 = require("./utils");
6
+ const close_webview_util_1 = require("./close-webview-util");
7
7
  /**
8
8
  * Сервис, отвечающий за взаимодействие WA с WV компонентами NA —
9
9
  * «заголовком» и кнопкой «назад».
@@ -24,7 +24,7 @@ class NativeNavigationAndTitleService {
24
24
  }
25
25
  // eslint-disable-next-line class-methods-use-this -- удобней использовать метод в контексте экземпляра.
26
26
  closeWebview() {
27
- (0, utils_1.closeWebviewUtil)();
27
+ (0, close_webview_util_1.closeWebviewUtil)();
28
28
  }
29
29
  goBack() {
30
30
  this.goBackAFewStepsClientSide(-1, true);
@@ -38,7 +38,7 @@ class NativeNavigationAndTitleService {
38
38
  const maxStepsToBack = this.nativeHistoryStack.length - 1;
39
39
  if (stepsToBack > maxStepsToBack) {
40
40
  if (autoCloseWebview) {
41
- (0, utils_1.closeWebviewUtil)();
41
+ (0, close_webview_util_1.closeWebviewUtil)();
42
42
  return;
43
43
  }
44
44
  this.numOfBackSteps = maxStepsToBack;
@@ -119,7 +119,7 @@ class NativeNavigationAndTitleService {
119
119
  this.nativeHistoryStack = this.nativeHistoryStack.slice(0, -this.numOfBackSteps);
120
120
  this.numOfBackSteps = 1;
121
121
  if (this.nativeHistoryStack.length < 1) {
122
- (0, utils_1.closeWebviewUtil)();
122
+ (0, close_webview_util_1.closeWebviewUtil)();
123
123
  return;
124
124
  }
125
125
  this.syncHistoryWithNative();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/bridge-to-native",
3
- "version": "1.3.2-beta.0084dcb",
3
+ "version": "1.3.2-beta.531b429",
4
4
  "license": "MIT",
5
5
  "description": "Утилита для удобной работы веб приложения внутри нативного приложения и коммуникации с ним.",
6
6
  "engines": {
@@ -1,2 +0,0 @@
1
- export declare function appendFromCurrentQueryParamForIos(nativeUrl: string): string;
2
- export declare const closeWebviewUtil: () => void;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.closeWebviewUtil = void 0;
4
- exports.appendFromCurrentQueryParamForIos = appendFromCurrentQueryParamForIos;
5
- const QUERY_CLOSE_WEBVIEW_KEY = 'closeWebView';
6
- const QUERY_CLOSE_WEBVIEW_VALUE = 'true';
7
- const QUERY_FROM_CURRENT_KEY = 'fromCurrent';
8
- const QUERY_FROM_CURRENT_VALUE = 'true';
9
- function appendFromCurrentQueryParamForIos(nativeUrl) {
10
- const qIndex = nativeUrl.indexOf('?');
11
- if (qIndex === -1) {
12
- return `${nativeUrl}?${QUERY_FROM_CURRENT_KEY}=${QUERY_FROM_CURRENT_VALUE}`;
13
- }
14
- const base = nativeUrl.slice(0, qIndex);
15
- const query = nativeUrl.slice(qIndex + 1);
16
- const params = new URLSearchParams(query);
17
- params.set(QUERY_FROM_CURRENT_KEY, QUERY_FROM_CURRENT_VALUE);
18
- return `${base}?${params.toString()}`;
19
- }
20
- const closeWebviewUtil = () => {
21
- const originalPageUrl = new URL(window.location.href);
22
- originalPageUrl.searchParams.set(QUERY_CLOSE_WEBVIEW_KEY, QUERY_CLOSE_WEBVIEW_VALUE);
23
- window.location.href = originalPageUrl.toString();
24
- };
25
- exports.closeWebviewUtil = closeWebviewUtil;