|
@@ -1,5 +1,4 @@
|
1
|
1
|
import React from 'react';
|
2
|
|
-import { v4 as uuid } from 'uuid';
|
3
|
2
|
|
4
|
3
|
import {
|
5
|
4
|
Image,
|
|
@@ -42,6 +41,11 @@ const RNCWebView = requireNativeComponent(
|
42
|
41
|
) as typeof NativeWebViewAndroid;
|
43
|
42
|
const { resolveAssetSource } = Image;
|
44
|
43
|
|
|
44
|
+/**
|
|
45
|
+ * A simple counter to uniquely identify WebView instances. Do not use this for anything else.
|
|
46
|
+ */
|
|
47
|
+let uniqueRef = 0;
|
|
48
|
+
|
45
|
49
|
/**
|
46
|
50
|
* Renders a native WebView.
|
47
|
51
|
*/
|
|
@@ -71,15 +75,14 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
71
|
75
|
lastErrorEvent: null,
|
72
|
76
|
};
|
73
|
77
|
|
74
|
|
- uniqueRef = uuid().replace(/-/g, '');
|
75
|
78
|
|
76
|
79
|
webViewRef = React.createRef<NativeWebViewAndroid>();
|
77
|
80
|
|
78
|
|
- componentDidMount = () => {
|
79
|
|
- BatchedBridge.registerCallableModule(this.getMessagingModuleName(), this);
|
80
|
|
- }
|
|
81
|
+ messagingModuleName = `WebViewMessageHandler${uniqueRef+=1}`;
|
81
|
82
|
|
82
|
|
- getMessagingModuleName = () => `WebViewMessageHandler${this.uniqueRef}`;
|
|
83
|
+ componentDidMount = () => {
|
|
84
|
+ BatchedBridge.registerCallableModule(this.messagingModuleName, this);
|
|
85
|
+ };
|
83
|
86
|
|
84
|
87
|
getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
|
85
|
88
|
|
|
@@ -338,7 +341,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
338
|
341
|
key="webViewKey"
|
339
|
342
|
{...otherProps}
|
340
|
343
|
messagingEnabled={typeof onMessage === 'function'}
|
341
|
|
- messagingModuleName={this.getMessagingModuleName()}
|
|
344
|
+ messagingModuleName={this.messagingModuleName}
|
342
|
345
|
onLoadingError={this.onLoadingError}
|
343
|
346
|
onLoadingFinish={this.onLoadingFinish}
|
344
|
347
|
onLoadingProgress={this.onLoadingProgress}
|