@webview-bridge/web 1.0.1 → 1.0.2
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/dist/commonjs/index.cjs
CHANGED
|
@@ -98,29 +98,34 @@ var linkNativeMethod = (options = {
|
|
|
98
98
|
if (!window.nativeEmitter) {
|
|
99
99
|
window.nativeEmitter = emitter;
|
|
100
100
|
}
|
|
101
|
-
const target = bridgeMethods.reduce(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
const target = bridgeMethods.reduce(
|
|
102
|
+
(acc, method) => {
|
|
103
|
+
return {
|
|
104
|
+
...acc,
|
|
105
|
+
[method]: (...args) => {
|
|
106
|
+
const eventId = createRandomId();
|
|
107
|
+
return Promise.race([
|
|
108
|
+
createResolver(emitter, method, eventId, () => {
|
|
109
|
+
window.ReactNativeWebView?.postMessage(
|
|
110
|
+
JSON.stringify({
|
|
111
|
+
type: "bridge",
|
|
112
|
+
body: {
|
|
113
|
+
method,
|
|
114
|
+
eventId,
|
|
115
|
+
args
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}),
|
|
120
|
+
timeout(timeoutMs)
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
isWebViewBridgeAvailable: Boolean(window.ReactNativeWebView) && bridgeMethods.length > 0
|
|
127
|
+
}
|
|
128
|
+
);
|
|
124
129
|
return new Proxy(target, {
|
|
125
130
|
get: (target2, method) => {
|
|
126
131
|
if (method in target2) {
|
package/dist/module/index.mjs
CHANGED
|
@@ -70,29 +70,34 @@ var linkNativeMethod = (options = {
|
|
|
70
70
|
if (!window.nativeEmitter) {
|
|
71
71
|
window.nativeEmitter = emitter;
|
|
72
72
|
}
|
|
73
|
-
const target = bridgeMethods.reduce(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
const target = bridgeMethods.reduce(
|
|
74
|
+
(acc, method) => {
|
|
75
|
+
return {
|
|
76
|
+
...acc,
|
|
77
|
+
[method]: (...args) => {
|
|
78
|
+
const eventId = createRandomId();
|
|
79
|
+
return Promise.race([
|
|
80
|
+
createResolver(emitter, method, eventId, () => {
|
|
81
|
+
window.ReactNativeWebView?.postMessage(
|
|
82
|
+
JSON.stringify({
|
|
83
|
+
type: "bridge",
|
|
84
|
+
body: {
|
|
85
|
+
method,
|
|
86
|
+
eventId,
|
|
87
|
+
args
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}),
|
|
92
|
+
timeout(timeoutMs)
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
isWebViewBridgeAvailable: Boolean(window.ReactNativeWebView) && bridgeMethods.length > 0
|
|
99
|
+
}
|
|
100
|
+
);
|
|
96
101
|
return new Proxy(target, {
|
|
97
102
|
get: (target2, method) => {
|
|
98
103
|
if (method in target2) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { WithAvailable } from "./types";
|
|
1
2
|
export interface LinkNativeMethodOptions<T extends object> {
|
|
2
3
|
timeout?: number;
|
|
3
4
|
throwOnError?: boolean | (keyof T)[];
|
|
4
5
|
onFallback?: (method: keyof T) => void;
|
|
5
6
|
}
|
|
6
|
-
export declare const linkNativeMethod: <T extends object>(options?: LinkNativeMethodOptions<T>) => T
|
|
7
|
+
export declare const linkNativeMethod: <T extends object>(options?: LinkNativeMethodOptions<T>) => WithAvailable<T>;
|
|
@@ -3,3 +3,6 @@ export type ProceduresObject<T extends Record<string, Procedure>> = {
|
|
|
3
3
|
[K in keyof T]: (...args: Parameters<T[K]>) => Promise<Awaited<ReturnType<T[K]>>>;
|
|
4
4
|
};
|
|
5
5
|
export type Bridge = <T extends Record<string, Procedure>>(procedures: T) => ProceduresObject<T>;
|
|
6
|
+
export type WithAvailable<T> = {
|
|
7
|
+
isWebViewBridgeAvailable: boolean;
|
|
8
|
+
} & T;
|