@webview-bridge/react-native 1.5.0 → 1.5.1-rc.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.
|
@@ -64,12 +64,16 @@ const createWebView = ({ bridge, debug, responseTimeout = 2000, postMessageSchem
|
|
|
64
64
|
webviewRefList.pop();
|
|
65
65
|
};
|
|
66
66
|
}, []);
|
|
67
|
-
const
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
const initData = (0, react_1.useMemo)(() => {
|
|
68
|
+
const bridgeMethods = Object.entries(bridge.getState() ?? {})
|
|
69
|
+
.filter(([_, bridge]) => typeof bridge === "function")
|
|
70
|
+
.map(([name]) => name);
|
|
71
|
+
const initialState = Object.fromEntries(Object.entries(bridge.getState() ?? {}).filter(([_, value]) => typeof value !== "function"));
|
|
72
|
+
return { bridgeMethods, initialState };
|
|
73
|
+
}, []);
|
|
74
|
+
(0, react_1.useEffect)(() => {
|
|
75
|
+
webviewRef.current?.injectJavaScript((0, bridge_1.SAFE_NATIVE_EMITTER_EMIT)("hydrate", initData));
|
|
76
|
+
}, [initData]);
|
|
73
77
|
(0, react_1.useImperativeHandle)(ref, () => webviewRef.current, []);
|
|
74
78
|
const handleMessage = async (event) => {
|
|
75
79
|
props.onMessage?.(event);
|
|
@@ -124,8 +128,8 @@ const createWebView = ({ bridge, debug, responseTimeout = 2000, postMessageSchem
|
|
|
124
128
|
}
|
|
125
129
|
};
|
|
126
130
|
return (<react_native_webview_1.default {...props} ref={webviewRef} onMessage={handleMessage} injectedJavaScriptBeforeContentLoaded={[
|
|
127
|
-
(0, bridge_1.INJECT_BRIDGE_METHODS)(
|
|
128
|
-
(0, bridge_1.INJECT_BRIDGE_STATE)(initialState),
|
|
131
|
+
(0, bridge_1.INJECT_BRIDGE_METHODS)(initData.bridgeMethods),
|
|
132
|
+
(0, bridge_1.INJECT_BRIDGE_STATE)(initData.initialState),
|
|
129
133
|
props.injectedJavaScriptBeforeContentLoaded,
|
|
130
134
|
"true;",
|
|
131
135
|
]
|
|
@@ -63,7 +63,7 @@ const handleBridge = async ({ bridge, method, args, webview, eventId, }) => {
|
|
|
63
63
|
};
|
|
64
64
|
exports.handleBridge = handleBridge;
|
|
65
65
|
const INJECT_BRIDGE_METHODS = (bridgeNames) => `
|
|
66
|
-
window.__bridgeMethods__ =
|
|
66
|
+
window.__bridgeMethods__ = ${JSON.stringify(bridgeNames)};
|
|
67
67
|
`;
|
|
68
68
|
exports.INJECT_BRIDGE_METHODS = INJECT_BRIDGE_METHODS;
|
|
69
69
|
const INJECT_BRIDGE_STATE = (initialState) => `
|
|
@@ -11,9 +11,10 @@ export interface EventEmitter<Events extends EventsMap = DefaultEvents> {
|
|
|
11
11
|
}>;
|
|
12
12
|
on<K extends keyof Events>(this: this, event: K, cb: Events[K]): () => void;
|
|
13
13
|
}
|
|
14
|
+
export type DefaultEmitter = EventEmitter<DefaultEvents>;
|
|
14
15
|
export declare const createEvents: <Events extends EventsMap = DefaultEvents>() => EventEmitter<Events>;
|
|
15
16
|
export interface CreateResolverOptions {
|
|
16
|
-
emitter:
|
|
17
|
+
emitter: DefaultEmitter;
|
|
17
18
|
evaluate: () => void;
|
|
18
19
|
eventId: string;
|
|
19
20
|
failHandler?: Error | false;
|
|
@@ -3,6 +3,7 @@ import type { AnySchema as YupTypeAny, InferType as yupInfer } from "yup";
|
|
|
3
3
|
import type { infer as zodInfer, ZodTypeAny } from "zod";
|
|
4
4
|
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
5
5
|
export type Primitive = string | number | boolean | null | undefined;
|
|
6
|
+
export type PrimitiveObject = Record<string, Primitive>;
|
|
6
7
|
export type RawJSON = Primitive | {
|
|
7
8
|
[key: string]: RawJSON;
|
|
8
9
|
} | RawJSONArray;
|
package/package.json
CHANGED