@alfalab/bridge-to-native 0.0.9-beta-648b4e7 → 0.0.10

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.
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
+ /* eslint-disable no-underscore-dangle */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.BridgeToNative = void 0;
4
- /* eslint-disable no-underscore-dangle */
5
- //@ts-nocheck
6
5
  const constants_1 = require("./constants");
7
6
  const native_fallbacks_1 = require("./native-fallbacks");
8
7
  const native_navigation_and_title_1 = require("./native-navigation-and-title");
@@ -16,11 +15,6 @@ class BridgeToNative {
16
15
  // Webview, запущенное в Android окружении имеет объект `Android` в window.
17
16
  this.AndroidBridge = window.Android;
18
17
  this.environment = this.AndroidBridge ? 'android' : 'ios';
19
- if (!(window === null || window === void 0 ? void 0 : window.locationReplaceStack)) {
20
- window.locationReplaceStack = [];
21
- console.log('window.locationReplaceStack created:');
22
- console.log(window.locationReplaceStack);
23
- }
24
18
  const previousState = !!sessionStorage.getItem(constants_1.PREVIOUS_B2N_STATE_STORAGE_KEY);
25
19
  if (previousState) {
26
20
  this.restorePreviousState();
@@ -110,22 +110,13 @@ class NativeFallbacks {
110
110
  const appId = (0, utils_1.getAppId)(environment, iosAppId);
111
111
  if (!forceOpenInWebview && this.b2n.canUseNativeFeature('linksInBrowser')) {
112
112
  url.searchParams.append('openInBrowser', 'true');
113
- window.locationReplaceStack.push(url.href);
114
- console.log('window.locationReplaceStack edited');
115
- console.log(window.locationReplaceStack);
116
113
  window.location.replace(url.href);
117
114
  }
118
115
  else if (iosAppId || checkAndroidAllowOpenInNewWebview()) {
119
- window.locationReplaceStack.push(`${appId}://webFeature?type=recommendation&url=${encodeURIComponent(url.href)}`);
120
- console.log('window.locationReplaceStack edited');
121
- console.log(window.locationReplaceStack);
122
116
  window.location.replace(`${appId}://webFeature?type=recommendation&url=${encodeURIComponent(url.href)}`);
123
117
  }
124
118
  else {
125
119
  (_a = this.b2n.nativeNavigationAndTitle) === null || _a === void 0 ? void 0 : _a.setInitialView('');
126
- window.locationReplaceStack.push(url.href);
127
- console.log('window.locationReplaceStack edited');
128
- console.log(window.locationReplaceStack);
129
120
  window.location.replace(url.href);
130
121
  }
131
122
  }
@@ -28,8 +28,9 @@ export declare class NativeNavigationAndTitle {
28
28
  goBackAFewSteps(stepsNumber: number, autoCloseWebview?: boolean): void;
29
29
  /**
30
30
  * @param path Путь для перехода на функциональность внутри приложения.
31
+ * @param historyState (https://developer.mozilla.org/en-US/docs/Web/API/History/state) для новой записи в истории.
31
32
  */
32
- handleRedirect(path: string): void;
33
+ handleRedirect(path: string, historyState?: Record<string, unknown>): void;
33
34
  /**
34
35
  * В этом варианте аргументы 2,3,4 соответствуют аргументам 1,2,3 метода `src/shared/utils/handle-redirect`.
35
36
  *
@@ -37,8 +38,9 @@ export declare class NativeNavigationAndTitle {
37
38
  * @param appName См. первый параметр `src/handle-redirect.ts`.
38
39
  * @param path См. второй параметр `src/handle-redirect.ts`.
39
40
  * @param params См. третий параметр `src/handle-redirect.ts`.
41
+ * @param historyState (https://developer.mozilla.org/en-US/docs/Web/API/History/state) для новой записи в истории.
40
42
  */
41
- handleRedirect(pageTitle: string, appName: string, path?: string, params?: Record<string, string>): void;
43
+ handleRedirect(pageTitle: string, appName: string, path?: string, params?: Record<string, string>, historyState?: Record<string, unknown>): void;
42
44
  /**
43
45
  * Информирует натив, что веб находится на первом экране (сбрасывает историю переходов, не влияя на браузерную
44
46
  * историю), а значит следующее нажатие на кнопку "Назад" в нативе закроет вебвью.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NativeNavigationAndTitle = void 0;
4
- //@ts-nocheck
5
4
  const constants_1 = require("./constants");
6
5
  const utils_1 = require("./utils");
7
6
  /**
@@ -68,15 +67,17 @@ class NativeNavigationAndTitle {
68
67
  * и регистрирует этот переход в приложении, чтобы кнопка «Назад» в Нативе вызывала
69
68
  * переход назад в вебе.
70
69
  */
71
- handleRedirect(pageTitleOrPath, appName, path, params) {
72
- if (appName) {
73
- this._handleWindowRedirect(appName, path, params);
70
+ handleRedirect(pageTitleOrPath, appNameOrHistoryState, path, params, historyState) {
71
+ const checkAppNameArgument = (argument) => Boolean(appNameOrHistoryState && typeof appNameOrHistoryState === 'string');
72
+ const isAppNameArgument = checkAppNameArgument(appNameOrHistoryState);
73
+ if (isAppNameArgument) {
74
+ this._handleWindowRedirect(appNameOrHistoryState, path, params, historyState);
74
75
  }
75
76
  else {
76
77
  const { appName: extractedAppName, path: extractedPath, query: extractedQuery, } = (0, utils_1.extractAppNameRouteAndQuery)(pageTitleOrPath);
77
- this._handleWindowRedirect(extractedAppName, extractedPath, extractedQuery);
78
+ this._handleWindowRedirect(extractedAppName, extractedPath, extractedQuery, appNameOrHistoryState);
78
79
  }
79
- const title = appName ? pageTitleOrPath : '';
80
+ const title = isAppNameArgument ? pageTitleOrPath : '';
80
81
  this.nativeHistoryStack.push(title);
81
82
  this.syncHistoryWithNative(title, 'navigation');
82
83
  }
@@ -144,23 +145,12 @@ class NativeNavigationAndTitle {
144
145
  if (this.b2n.environment === 'ios') {
145
146
  if (closeIOSWebviewBeforeCallNativeDeeplinkHandler) {
146
147
  this.b2n.closeWebview();
147
- setTimeout(() => {
148
- window.locationReplaceStack.push(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
149
- console.log('window.locationReplaceStack edited');
150
- console.log(window.locationReplaceStack);
151
- window.location.replace(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
152
- }, 0);
148
+ setTimeout(() => window.location.replace(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`), 0);
153
149
  return;
154
150
  }
155
- window.locationReplaceStack.push(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
156
- console.log('window.locationReplaceStack edited');
157
- console.log(window.locationReplaceStack);
158
151
  window.location.replace(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
159
152
  }
160
153
  else {
161
- window.locationReplaceStack.push(`alfabank://${clearedDeeplinkPath}`);
162
- console.log('window.locationReplaceStack edited');
163
- console.log(window.locationReplaceStack);
164
154
  window.location.replace(`alfabank://${clearedDeeplinkPath}`);
165
155
  }
166
156
  }
@@ -286,9 +276,6 @@ class NativeNavigationAndTitle {
286
276
  const pageIdStr = pageId ? `&pageId=${pageId}` : '';
287
277
  const paramsToSend = `ios:setPageSettings/${pageTitleStr + pageIdStr}`;
288
278
  if (this.lastSetPageSettingsParams !== paramsToSend) {
289
- window.locationReplaceStack.push(paramsToSend);
290
- console.log('window.locationReplaceStack edited');
291
- console.log(window.locationReplaceStack);
292
279
  window.location.replace(paramsToSend);
293
280
  this.lastSetPageSettingsParams = paramsToSend;
294
281
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "UNLICENSED",
3
3
  "name": "@alfalab/bridge-to-native",
4
- "version": "0.0.9-beta-648b4e7",
4
+ "version": "0.0.10",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/core-ds/bridge-to-native.git"
package/types.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare type PreviousNativeNavigationAndTitleState = {
30
30
  title: string;
31
31
  };
32
32
  export declare type SyncPurpose = 'initialization' | 'navigation' | 'title-replacing';
33
- export declare type HandleRedirect = (appName: string, path?: string, params?: Record<string, string>) => void;
33
+ export declare type HandleRedirect = (appName: string, path?: string, params?: Record<string, string>, historyState?: Record<string, unknown>) => void;
34
34
  export declare type Theme = 'light' | 'dark';
35
35
  export declare type ExternalNavigationOptions = {
36
36
  onClick?: () => void;