@alfalab/bridge-to-native 0.0.9-beta-fa134e1 → 0.0.9-beta-37f9ff1
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,9 +12,6 @@ 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';
|
|
@@ -21,6 +19,7 @@ class BridgeToNative {
|
|
|
21
19
|
if (previousState) {
|
|
22
20
|
this.restorePreviousState();
|
|
23
21
|
this.nativeFallbacks = new native_fallbacks_1.NativeFallbacks(this);
|
|
22
|
+
this._blankPagePath = blankPagePath;
|
|
24
23
|
return;
|
|
25
24
|
}
|
|
26
25
|
this._appVersion =
|
|
@@ -30,9 +29,11 @@ class BridgeToNative {
|
|
|
30
29
|
this._iosAppId = this.getIosAppId(nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.iosAppId);
|
|
31
30
|
this._theme = (nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.theme) === 'dark' ? 'dark' : 'light';
|
|
32
31
|
this._originalWebviewParams = (nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.originalWebviewParams) || '';
|
|
33
|
-
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this,
|
|
32
|
+
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this, nativeParams ? nativeParams.nextPageId : null, nativeParams === null || nativeParams === void 0 ? void 0 : nativeParams.title, handleRedirect);
|
|
33
|
+
this._handleRedirect = handleRedirect;
|
|
34
34
|
this.nextPageId = nativeParams ? nativeParams.nextPageId : null;
|
|
35
35
|
this.nativeFallbacks = new native_fallbacks_1.NativeFallbacks(this);
|
|
36
|
+
this._blankPagePath = blankPagePath;
|
|
36
37
|
}
|
|
37
38
|
get nativeNavigationAndTitle() {
|
|
38
39
|
return this._nativeNavigationAndTitle;
|
|
@@ -105,7 +106,7 @@ class BridgeToNative {
|
|
|
105
106
|
appVersion: this._appVersion,
|
|
106
107
|
theme: this._theme,
|
|
107
108
|
nextPageId: this.nextPageId,
|
|
108
|
-
originalWebviewParams: this.
|
|
109
|
+
originalWebviewParams: this._originalWebviewParams || '',
|
|
109
110
|
iosAppId: this._iosAppId,
|
|
110
111
|
};
|
|
111
112
|
sessionStorage.setItem(constants_1.PREVIOUS_B2N_STATE_STORAGE_KEY, JSON.stringify(currentState));
|
|
@@ -138,7 +139,7 @@ class BridgeToNative {
|
|
|
138
139
|
this._theme = previousState.theme;
|
|
139
140
|
this._originalWebviewParams = previousState.originalWebviewParams;
|
|
140
141
|
this.nextPageId = previousState.nextPageId;
|
|
141
|
-
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this, previousState.nextPageId, '', this.
|
|
142
|
+
this._nativeNavigationAndTitle = new native_navigation_and_title_1.NativeNavigationAndTitle(this, previousState.nextPageId, '', this._handleRedirect);
|
|
142
143
|
sessionStorage.removeItem(constants_1.PREVIOUS_B2N_STATE_STORAGE_KEY);
|
|
143
144
|
}
|
|
144
145
|
}
|
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,7 +105,7 @@ 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')) {
|
|
@@ -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
|
/**
|
|
@@ -276,7 +274,7 @@ class NativeNavigationAndTitle {
|
|
|
276
274
|
const pageIdStr = pageId ? `&pageId=${pageId}` : '';
|
|
277
275
|
const paramsToSend = `ios:setPageSettings/${pageTitleStr + pageIdStr}`;
|
|
278
276
|
if (this.lastSetPageSettingsParams !== paramsToSend) {
|
|
279
|
-
window.location.replace(paramsToSend);
|
|
277
|
+
// window.location.replace(paramsToSend);
|
|
280
278
|
this.lastSetPageSettingsParams = paramsToSend;
|
|
281
279
|
}
|
|
282
280
|
}
|
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'> & {
|