Browse Source

fix(Android): Resolve crypto error with uuid usage (#1334)

* fix(Android): uuid generation issue

* chore: remove redundant types/uuid dependency

* refactor(Android): replace uuid function with unique instance counter
Artur Yorsh 4 years ago
parent
commit
438e29298b
No account linked to committer's email address
2 changed files with 11 additions and 10 deletions
  1. 1
    3
      package.json
  2. 10
    7
      src/WebView.android.tsx

+ 1
- 3
package.json View File

@@ -34,8 +34,7 @@
34 34
   },
35 35
   "dependencies": {
36 36
     "escape-string-regexp": "2.0.0",
37
-    "invariant": "2.2.4",
38
-    "uuid": "^7.0.3"
37
+    "invariant": "2.2.4"
39 38
   },
40 39
   "devDependencies": {
41 40
     "@babel/core": "7.4.5",
@@ -48,7 +47,6 @@
48 47
     "@types/jest": "24.0.18",
49 48
     "@types/react": "16.8.8",
50 49
     "@types/react-native": "0.60.11",
51
-    "@types/uuid": "^7.0.2",
52 50
     "@typescript-eslint/eslint-plugin": "2.1.0",
53 51
     "@typescript-eslint/parser": "2.1.0",
54 52
     "babel-eslint": "10.0.3",

+ 10
- 7
src/WebView.android.tsx View File

@@ -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}