@alfalab/bridge-to-native 0.0.9-beta-fa134e1 → 0.0.9-beta-d3ad282
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.
package/bridge-to-native.d.ts
CHANGED
|
@@ -6,16 +6,15 @@ import type { Environment, HandleRedirect, NativeFeatureKey, NativeParams, Theme
|
|
|
6
6
|
* для использования в вебвью окружении.
|
|
7
7
|
*/
|
|
8
8
|
export declare class BridgeToNative {
|
|
9
|
-
private readonly handleRedirect;
|
|
10
|
-
private readonly blankPagePath;
|
|
11
|
-
private readonly nativeParams?;
|
|
12
9
|
readonly AndroidBridge: {
|
|
13
10
|
setPageSettings: (params: string) => void;
|
|
14
11
|
} | undefined;
|
|
15
12
|
readonly environment: Environment;
|
|
16
13
|
readonly nativeFallbacks: NativeFallbacks;
|
|
17
14
|
private nextPageId;
|
|
18
|
-
|
|
15
|
+
private readonly _blankPagePath;
|
|
16
|
+
private readonly _handleRedirect;
|
|
17
|
+
constructor(handleRedirect: HandleRedirect, blankPagePath: string, nativeParams?: NativeParams);
|
|
19
18
|
private _nativeNavigationAndTitle;
|
|
20
19
|
get nativeNavigationAndTitle(): NativeNavigationAndTitle;
|
|
21
20
|
private _originalWebviewParams;
|
package/bridge-to-native.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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
5
|
const constants_1 = require("./constants");
|
|
@@ -11,16 +12,16 @@ const utils_1 = require("./utils");
|
|
|
11
12
|
*/
|
|
12
13
|
class BridgeToNative {
|
|
13
14
|
constructor(handleRedirect, blankPagePath, nativeParams) {
|
|
14
|
-
this.handleRedirect = handleRedirect;
|
|
15
|
-
this.blankPagePath = blankPagePath;
|
|
16
|
-
this.nativeParams = nativeParams;
|
|
17
15
|
// Webview, запущенное в Android окружении имеет объект `Android` в window.
|
|
18
16
|
this.AndroidBridge = window.Android;
|
|
19
17
|
this.environment = this.AndroidBridge ? 'android' : 'ios';
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
window.locationReplaceStack = [];
|
|
20
20
|
const previousState = !!sessionStorage.getItem(constants_1.PREVIOUS_B2N_STATE_STORAGE_KEY);
|
|
21
21
|
if (previousState) {
|
|
22
22
|
this.restorePreviousState();
|
|
23
23
|
this.nativeFallbacks = new native_fallbacks_1.NativeFallbacks(this);
|
|
24
|
+
this._blankPagePath = blankPagePath;
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
27
|
this._appVersion =
|
|
@@ -30,9 +31,11 @@ class BridgeToNative {
|
|
|
30
31
|
this._iosAppId = this.getIosAppId(nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.iosAppId);
|
|
31
32
|
this._theme = (nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.theme) === 'dark' ? 'dark' : 'light';
|
|
32
33
|
this._originalWebviewParams = (nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.originalWebviewParams) || '';
|
|
33
|
-
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this,
|
|
34
|
+
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this, nativeParams ? nativeParams.nextPageId : null, nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.title, handleRedirect);
|
|
35
|
+
this._handleRedirect = handleRedirect;
|
|
34
36
|
this.nextPageId = nativeParams ? nativeParams.nextPageId : null;
|
|
35
37
|
this.nativeFallbacks = new native_fallbacks_1.NativeFallbacks(this);
|
|
38
|
+
this._blankPagePath = blankPagePath;
|
|
36
39
|
}
|
|
37
40
|
get nativeNavigationAndTitle() {
|
|
38
41
|
return this._nativeNavigationAndTitle;
|
|
@@ -105,7 +108,7 @@ class BridgeToNative {
|
|
|
105
108
|
appVersion: this._appVersion,
|
|
106
109
|
theme: this._theme,
|
|
107
110
|
nextPageId: this.nextPageId,
|
|
108
|
-
originalWebviewParams: this.
|
|
111
|
+
originalWebviewParams: this._originalWebviewParams || '',
|
|
109
112
|
iosAppId: this._iosAppId,
|
|
110
113
|
};
|
|
111
114
|
sessionStorage.setItem(constants_1.PREVIOUS_B2N_STATE_STORAGE_KEY, JSON.stringify(currentState));
|
|
@@ -138,7 +141,7 @@ class BridgeToNative {
|
|
|
138
141
|
this._theme = previousState.theme;
|
|
139
142
|
this._originalWebviewParams = previousState.originalWebviewParams;
|
|
140
143
|
this.nextPageId = previousState.nextPageId;
|
|
141
|
-
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this, previousState.nextPageId, '', this.
|
|
144
|
+
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this, previousState.nextPageId, '', this._handleRedirect);
|
|
142
145
|
sessionStorage.removeItem(constants_1.PREVIOUS_B2N_STATE_STORAGE_KEY);
|
|
143
146
|
}
|
|
144
147
|
}
|
package/native-fallbacks.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { BridgeToNative } from './bridge-to-native';
|
|
|
4
4
|
* Класс содержит реализацию обходных путей для веб-фич, которые не работают в нативном-вебвью.
|
|
5
5
|
*/
|
|
6
6
|
export declare class NativeFallbacks {
|
|
7
|
-
private
|
|
7
|
+
private b2n;
|
|
8
8
|
constructor(b2n: BridgeToNative);
|
|
9
9
|
/**
|
|
10
10
|
* Метод, возвращающий пропсы для ссылок, ведущих на ВНЕШНИЙ ресурс. Которые просто
|
package/native-fallbacks.js
CHANGED
|
@@ -41,7 +41,7 @@ class NativeFallbacks {
|
|
|
41
41
|
*/
|
|
42
42
|
getExternalLinkProps(link, options = {}) {
|
|
43
43
|
const { onClick, forceOpenInWebview } = options;
|
|
44
|
-
const { iosAppId, environment, checkAndroidAllowOpenInNewWebview } = this.b2n;
|
|
44
|
+
const { iosAppId, environment, appVersion, checkAndroidAllowOpenInNewWebview } = this.b2n;
|
|
45
45
|
const url = (0, utils_1.getUrlInstance)(link);
|
|
46
46
|
const appId = (0, utils_1.getAppId)(environment, iosAppId);
|
|
47
47
|
if (!forceOpenInWebview && this.b2n.canUseNativeFeature('linksInBrowser')) {
|
|
@@ -105,18 +105,24 @@ class NativeFallbacks {
|
|
|
105
105
|
*/
|
|
106
106
|
visitExternalResource(link, forceOpenInWebview = false) {
|
|
107
107
|
var _a;
|
|
108
|
-
const { iosAppId, environment, checkAndroidAllowOpenInNewWebview } = this.b2n;
|
|
108
|
+
const { iosAppId, appVersion, environment, checkAndroidAllowOpenInNewWebview } = this.b2n;
|
|
109
109
|
const url = (0, utils_1.getUrlInstance)(link);
|
|
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
|
+
// @ts-ignore
|
|
114
|
+
window.locationReplaceStack.push(url.href);
|
|
113
115
|
window.location.replace(url.href);
|
|
114
116
|
}
|
|
115
117
|
else if (iosAppId || checkAndroidAllowOpenInNewWebview()) {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
window.locationReplaceStack.push(`${appId}://webFeature?type=recommendation&url=${encodeURIComponent(url.href)}`);
|
|
116
120
|
window.location.replace(`${appId}://webFeature?type=recommendation&url=${encodeURIComponent(url.href)}`);
|
|
117
121
|
}
|
|
118
122
|
else {
|
|
119
123
|
(_a = this.b2n.nativeNavigationAndTitle) === null || _a === void 0 ? void 0 : _a.setInitialView('');
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
window.locationReplaceStack.push(url.href);
|
|
120
126
|
window.location.replace(url.href);
|
|
121
127
|
}
|
|
122
128
|
}
|
|
@@ -4,14 +4,12 @@ import { BridgeToNative } from './bridge-to-native';
|
|
|
4
4
|
* Класс, отвечающий за взаимодействие с нативными элементами в приложении – заголовком и нативной кнопкой назад.
|
|
5
5
|
*/
|
|
6
6
|
export declare class NativeNavigationAndTitle {
|
|
7
|
-
private
|
|
8
|
-
private readonly pageId;
|
|
9
|
-
private readonly initialNativeTitle;
|
|
10
|
-
private readonly handleWindowRedirect;
|
|
7
|
+
private b2n;
|
|
11
8
|
private nativeHistoryStack;
|
|
12
9
|
private numOfBackSteps;
|
|
13
10
|
private lastSetPageSettingsParams;
|
|
14
|
-
|
|
11
|
+
private readonly _handleWindowRedirect;
|
|
12
|
+
constructor(b2n: BridgeToNative, pageId: number | null, initialNativeTitle: string | undefined, handleWindowRedirect: HandleRedirect);
|
|
15
13
|
/**
|
|
16
14
|
* Метод, вызывающий `history.back()` или закрывающий вебвью, если нет записей
|
|
17
15
|
* в истории переходов.
|
|
@@ -9,15 +9,13 @@ const utils_1 = require("./utils");
|
|
|
9
9
|
class NativeNavigationAndTitle {
|
|
10
10
|
constructor(b2n, pageId, initialNativeTitle = '', handleWindowRedirect) {
|
|
11
11
|
this.b2n = b2n;
|
|
12
|
-
this.pageId = pageId;
|
|
13
|
-
this.initialNativeTitle = initialNativeTitle;
|
|
14
|
-
this.handleWindowRedirect = handleWindowRedirect;
|
|
15
12
|
this.nativeHistoryStack = [''];
|
|
16
13
|
this.numOfBackSteps = 1;
|
|
17
14
|
// Тут сохраняются параметры, которые в последний раз были отправлены в приложение.
|
|
18
15
|
// Просто, чтобы не слать одинаковые сигналы в приложение.
|
|
19
16
|
this.lastSetPageSettingsParams = '';
|
|
20
17
|
this.handleBack = this.handleBack.bind(this);
|
|
18
|
+
this._handleWindowRedirect = handleWindowRedirect;
|
|
21
19
|
const previousState = !!sessionStorage.getItem(constants_1.PREVIOUS_NATIVE_NAVIGATION_AND_TITLE_STATE_STORAGE_KEY);
|
|
22
20
|
if (pageId) {
|
|
23
21
|
this.supportSharedSession(pageId, initialNativeTitle);
|
|
@@ -65,17 +63,17 @@ class NativeNavigationAndTitle {
|
|
|
65
63
|
window.history.go(-this.numOfBackSteps);
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
|
-
* Метод вызывает handle-redirect
|
|
69
|
-
* приложении, чтобы кнопка «Назад» в Нативе вызывала
|
|
66
|
+
* Метод вызывает `src/shared/utils/handle-redirect` из `newclick-host-ui`
|
|
67
|
+
* и регистрирует этот переход в приложении, чтобы кнопка «Назад» в Нативе вызывала
|
|
70
68
|
* переход назад в вебе.
|
|
71
69
|
*/
|
|
72
70
|
handleRedirect(pageTitleOrPath, appName, path, params) {
|
|
73
71
|
if (appName) {
|
|
74
|
-
this.
|
|
72
|
+
this._handleWindowRedirect(appName, path, params);
|
|
75
73
|
}
|
|
76
74
|
else {
|
|
77
75
|
const { appName: extractedAppName, path: extractedPath, query: extractedQuery, } = (0, utils_1.extractAppNameRouteAndQuery)(pageTitleOrPath);
|
|
78
|
-
this.
|
|
76
|
+
this._handleWindowRedirect(extractedAppName, extractedPath, extractedQuery);
|
|
79
77
|
}
|
|
80
78
|
const title = appName ? pageTitleOrPath : '';
|
|
81
79
|
this.nativeHistoryStack.push(title);
|
|
@@ -129,7 +127,7 @@ class NativeNavigationAndTitle {
|
|
|
129
127
|
// В b2n этот метод отмечен модификатором доступа private, но тут его нужно вызвать
|
|
130
128
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
131
129
|
// @ts-ignore
|
|
132
|
-
this.handleRedirect(this.b2n.
|
|
130
|
+
this.handleRedirect(this.b2n._blankPagePath);
|
|
133
131
|
this.goBack();
|
|
134
132
|
}
|
|
135
133
|
/**
|
|
@@ -145,12 +143,20 @@ class NativeNavigationAndTitle {
|
|
|
145
143
|
if (this.b2n.environment === 'ios') {
|
|
146
144
|
if (closeIOSWebviewBeforeCallNativeDeeplinkHandler) {
|
|
147
145
|
this.b2n.closeWebview();
|
|
148
|
-
setTimeout(() =>
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
window.locationReplaceStack.push(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
|
|
149
|
+
window.location.replace(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
|
|
150
|
+
}, 0);
|
|
149
151
|
return;
|
|
150
152
|
}
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
window.locationReplaceStack.push(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
|
|
151
155
|
window.location.replace(`${this.b2n.iosAppId}://${clearedDeeplinkPath}`);
|
|
152
156
|
}
|
|
153
157
|
else {
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
window.locationReplaceStack.push(`alfabank://${clearedDeeplinkPath}`);
|
|
154
160
|
window.location.replace(`alfabank://${clearedDeeplinkPath}`);
|
|
155
161
|
}
|
|
156
162
|
}
|
|
@@ -276,6 +282,8 @@ class NativeNavigationAndTitle {
|
|
|
276
282
|
const pageIdStr = pageId ? `&pageId=${pageId}` : '';
|
|
277
283
|
const paramsToSend = `ios:setPageSettings/${pageTitleStr + pageIdStr}`;
|
|
278
284
|
if (this.lastSetPageSettingsParams !== paramsToSend) {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
window.locationReplaceStack.push(paramsToSend);
|
|
279
287
|
window.location.replace(paramsToSend);
|
|
280
288
|
this.lastSetPageSettingsParams = paramsToSend;
|
|
281
289
|
}
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare type WebViewWindow = Window & {
|
|
|
19
19
|
Android?: {
|
|
20
20
|
setPageSettings: (params: string) => void;
|
|
21
21
|
};
|
|
22
|
+
handleRedirect?: (appName: string, path?: string, params?: Record<string, string>) => VoidFunction;
|
|
22
23
|
};
|
|
23
24
|
export declare type PdfType = 'pdfFile' | 'base64' | 'binary';
|
|
24
25
|
export declare type PreviousBridgeToNativeState = Omit<NativeParams, 'title' | 'theme'> & {
|