@webview-bridge/react-native 1.7.0 → 1.7.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/index.cjs +24 -15
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +24 -15
- package/package.json +5 -5
- package/src/createWebView.tsx +21 -5
package/dist/index.cjs
CHANGED
|
@@ -680,31 +680,40 @@ var createWebView = function(param) {
|
|
|
680
680
|
* Sends an event from React Native to the Web.
|
|
681
681
|
* @link https://gronxb.github.io/webview-bridge/using-a-post-message.html
|
|
682
682
|
*/ postMessage: function(eventName, args) {
|
|
683
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
684
|
+
broadcast: false
|
|
685
|
+
};
|
|
686
|
+
var _lastRef_current;
|
|
683
687
|
var _args = args;
|
|
684
688
|
if (postMessageSchema2) {
|
|
685
689
|
_args = postMessageSchema2[eventName].validate(args);
|
|
686
690
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
for(var _iterator = webviewRefList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
690
|
-
var ref = _step.value;
|
|
691
|
-
var _ref_current;
|
|
692
|
-
ref === null || ref === void 0 ? void 0 : (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.injectJavaScript(SAFE_NATIVE_EMITTER_EMIT("postMessage/".concat(String(eventName)), _args));
|
|
693
|
-
}
|
|
694
|
-
} catch (err) {
|
|
695
|
-
_didIteratorError = true;
|
|
696
|
-
_iteratorError = err;
|
|
697
|
-
} finally{
|
|
691
|
+
if (options.broadcast) {
|
|
692
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
698
693
|
try {
|
|
699
|
-
|
|
700
|
-
|
|
694
|
+
for(var _iterator = webviewRefList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
695
|
+
var ref = _step.value;
|
|
696
|
+
var _ref_current;
|
|
697
|
+
ref === null || ref === void 0 ? void 0 : (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.injectJavaScript(SAFE_NATIVE_EMITTER_EMIT("postMessage/".concat(String(eventName)), _args));
|
|
701
698
|
}
|
|
699
|
+
} catch (err) {
|
|
700
|
+
_didIteratorError = true;
|
|
701
|
+
_iteratorError = err;
|
|
702
702
|
} finally{
|
|
703
|
-
|
|
704
|
-
|
|
703
|
+
try {
|
|
704
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
705
|
+
_iterator.return();
|
|
706
|
+
}
|
|
707
|
+
} finally{
|
|
708
|
+
if (_didIteratorError) {
|
|
709
|
+
throw _iteratorError;
|
|
710
|
+
}
|
|
705
711
|
}
|
|
706
712
|
}
|
|
713
|
+
return;
|
|
707
714
|
}
|
|
715
|
+
var lastRef = webviewRefList[webviewRefList.length - 1];
|
|
716
|
+
lastRef === null || lastRef === void 0 ? void 0 : (_lastRef_current = lastRef.current) === null || _lastRef_current === void 0 ? void 0 : _lastRef_current.injectJavaScript(SAFE_NATIVE_EMITTER_EMIT("postMessage/".concat(String(eventName)), _args));
|
|
708
717
|
},
|
|
709
718
|
WebView: (0, import_react.forwardRef)(function(props, ref) {
|
|
710
719
|
var webviewRef = (0, import_react.useRef)(null);
|
package/dist/index.d.cts
CHANGED
|
@@ -92,7 +92,13 @@ declare const createWebView: <BridgeObject extends Bridge, PostMessageSchema ext
|
|
|
92
92
|
* Sends an event from React Native to the Web.
|
|
93
93
|
* @link https://gronxb.github.io/webview-bridge/using-a-post-message.html
|
|
94
94
|
*/
|
|
95
|
-
postMessage: <EventName extends KeyOfOrString<PostMessageSchema>, Args extends Parser<PostMessageSchema, EventName>>(eventName: EventName, args: Args
|
|
95
|
+
postMessage: <EventName extends KeyOfOrString<PostMessageSchema>, Args extends Parser<PostMessageSchema, EventName>>(eventName: EventName, args: Args, options?: {
|
|
96
|
+
/**
|
|
97
|
+
* If `true`, the message will be broadcasted to all webviews.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
broadcast: boolean;
|
|
101
|
+
}) => void;
|
|
96
102
|
WebView: React.ForwardRefExoticComponent<react_native_webview_lib_WebViewTypes.IOSWebViewProps & react_native_webview_lib_WebViewTypes.AndroidWebViewProps & react_native_webview_lib_WebViewTypes.WindowsWebViewProps & React.RefAttributes<BridgeWebView>>;
|
|
97
103
|
/**
|
|
98
104
|
* @deprecated Use `postMessage` instead. And complete the type through the `postMessageSchema` option.
|
package/dist/index.d.ts
CHANGED
|
@@ -92,7 +92,13 @@ declare const createWebView: <BridgeObject extends Bridge, PostMessageSchema ext
|
|
|
92
92
|
* Sends an event from React Native to the Web.
|
|
93
93
|
* @link https://gronxb.github.io/webview-bridge/using-a-post-message.html
|
|
94
94
|
*/
|
|
95
|
-
postMessage: <EventName extends KeyOfOrString<PostMessageSchema>, Args extends Parser<PostMessageSchema, EventName>>(eventName: EventName, args: Args
|
|
95
|
+
postMessage: <EventName extends KeyOfOrString<PostMessageSchema>, Args extends Parser<PostMessageSchema, EventName>>(eventName: EventName, args: Args, options?: {
|
|
96
|
+
/**
|
|
97
|
+
* If `true`, the message will be broadcasted to all webviews.
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
broadcast: boolean;
|
|
101
|
+
}) => void;
|
|
96
102
|
WebView: React.ForwardRefExoticComponent<react_native_webview_lib_WebViewTypes.IOSWebViewProps & react_native_webview_lib_WebViewTypes.AndroidWebViewProps & react_native_webview_lib_WebViewTypes.WindowsWebViewProps & React.RefAttributes<BridgeWebView>>;
|
|
97
103
|
/**
|
|
98
104
|
* @deprecated Use `postMessage` instead. And complete the type through the `postMessageSchema` option.
|
package/dist/index.js
CHANGED
|
@@ -590,31 +590,40 @@ var createWebView = function(param) {
|
|
|
590
590
|
* Sends an event from React Native to the Web.
|
|
591
591
|
* @link https://gronxb.github.io/webview-bridge/using-a-post-message.html
|
|
592
592
|
*/ postMessage: function(eventName, args) {
|
|
593
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
594
|
+
broadcast: false
|
|
595
|
+
};
|
|
596
|
+
var _lastRef_current;
|
|
593
597
|
var _args = args;
|
|
594
598
|
if (postMessageSchema2) {
|
|
595
599
|
_args = postMessageSchema2[eventName].validate(args);
|
|
596
600
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
for(var _iterator = webviewRefList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
600
|
-
var ref = _step.value;
|
|
601
|
-
var _ref_current;
|
|
602
|
-
ref === null || ref === void 0 ? void 0 : (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.injectJavaScript(SAFE_NATIVE_EMITTER_EMIT("postMessage/".concat(String(eventName)), _args));
|
|
603
|
-
}
|
|
604
|
-
} catch (err) {
|
|
605
|
-
_didIteratorError = true;
|
|
606
|
-
_iteratorError = err;
|
|
607
|
-
} finally{
|
|
601
|
+
if (options.broadcast) {
|
|
602
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
608
603
|
try {
|
|
609
|
-
|
|
610
|
-
|
|
604
|
+
for(var _iterator = webviewRefList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
605
|
+
var ref = _step.value;
|
|
606
|
+
var _ref_current;
|
|
607
|
+
ref === null || ref === void 0 ? void 0 : (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.injectJavaScript(SAFE_NATIVE_EMITTER_EMIT("postMessage/".concat(String(eventName)), _args));
|
|
611
608
|
}
|
|
609
|
+
} catch (err) {
|
|
610
|
+
_didIteratorError = true;
|
|
611
|
+
_iteratorError = err;
|
|
612
612
|
} finally{
|
|
613
|
-
|
|
614
|
-
|
|
613
|
+
try {
|
|
614
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
615
|
+
_iterator.return();
|
|
616
|
+
}
|
|
617
|
+
} finally{
|
|
618
|
+
if (_didIteratorError) {
|
|
619
|
+
throw _iteratorError;
|
|
620
|
+
}
|
|
615
621
|
}
|
|
616
622
|
}
|
|
623
|
+
return;
|
|
617
624
|
}
|
|
625
|
+
var lastRef = webviewRefList[webviewRefList.length - 1];
|
|
626
|
+
lastRef === null || lastRef === void 0 ? void 0 : (_lastRef_current = lastRef.current) === null || _lastRef_current === void 0 ? void 0 : _lastRef_current.injectJavaScript(SAFE_NATIVE_EMITTER_EMIT("postMessage/".concat(String(eventName)), _args));
|
|
618
627
|
},
|
|
619
628
|
WebView: forwardRef(function(props, ref) {
|
|
620
629
|
var webviewRef = useRef(null);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webview-bridge/react-native",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fully Type-Safe Integration for React Native WebView and Web",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"react-native": "src/index.ts",
|
|
10
10
|
"exports": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"react-native-webview": "*"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@webview-bridge/utils": "1.7.
|
|
43
|
-
"@webview-bridge/types": "1.7.
|
|
42
|
+
"@webview-bridge/utils": "1.7.2",
|
|
43
|
+
"@webview-bridge/types": "1.7.2",
|
|
44
44
|
"use-sync-external-store": "^1.2.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
package/src/createWebView.tsx
CHANGED
|
@@ -152,17 +152,33 @@ export const createWebView = <
|
|
|
152
152
|
>(
|
|
153
153
|
eventName: EventName,
|
|
154
154
|
args: Args,
|
|
155
|
+
options: {
|
|
156
|
+
/**
|
|
157
|
+
* If `true`, the message will be broadcasted to all webviews.
|
|
158
|
+
* @default false
|
|
159
|
+
*/
|
|
160
|
+
broadcast: boolean;
|
|
161
|
+
} = {
|
|
162
|
+
broadcast: false,
|
|
163
|
+
},
|
|
155
164
|
) => {
|
|
156
165
|
let _args: any = args;
|
|
157
166
|
if (postMessageSchema) {
|
|
158
167
|
_args = postMessageSchema[eventName].validate(args);
|
|
159
168
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
if (options.broadcast) {
|
|
170
|
+
for (const ref of webviewRefList) {
|
|
171
|
+
ref?.current?.injectJavaScript(
|
|
172
|
+
SAFE_NATIVE_EMITTER_EMIT(`postMessage/${String(eventName)}`, _args),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
165
176
|
}
|
|
177
|
+
|
|
178
|
+
const lastRef = webviewRefList[webviewRefList.length - 1];
|
|
179
|
+
lastRef?.current?.injectJavaScript(
|
|
180
|
+
SAFE_NATIVE_EMITTER_EMIT(`postMessage/${String(eventName)}`, _args),
|
|
181
|
+
);
|
|
166
182
|
},
|
|
167
183
|
WebView: forwardRef<BridgeWebView, WebViewProps>((props, ref) => {
|
|
168
184
|
const webviewRef = useRef<WebView>(null);
|