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
   },
34
   },
35
   "dependencies": {
35
   "dependencies": {
36
     "escape-string-regexp": "2.0.0",
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
   "devDependencies": {
39
   "devDependencies": {
41
     "@babel/core": "7.4.5",
40
     "@babel/core": "7.4.5",
48
     "@types/jest": "24.0.18",
47
     "@types/jest": "24.0.18",
49
     "@types/react": "16.8.8",
48
     "@types/react": "16.8.8",
50
     "@types/react-native": "0.60.11",
49
     "@types/react-native": "0.60.11",
51
-    "@types/uuid": "^7.0.2",
52
     "@typescript-eslint/eslint-plugin": "2.1.0",
50
     "@typescript-eslint/eslint-plugin": "2.1.0",
53
     "@typescript-eslint/parser": "2.1.0",
51
     "@typescript-eslint/parser": "2.1.0",
54
     "babel-eslint": "10.0.3",
52
     "babel-eslint": "10.0.3",

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

1
 import React from 'react';
1
 import React from 'react';
2
-import { v4 as uuid } from 'uuid';
3
 
2
 
4
 import {
3
 import {
5
   Image,
4
   Image,
42
 ) as typeof NativeWebViewAndroid;
41
 ) as typeof NativeWebViewAndroid;
43
 const { resolveAssetSource } = Image;
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
  * Renders a native WebView.
50
  * Renders a native WebView.
47
  */
51
  */
71
     lastErrorEvent: null,
75
     lastErrorEvent: null,
72
   };
76
   };
73
 
77
 
74
-  uniqueRef = uuid().replace(/-/g, '');
75
 
78
 
76
   webViewRef = React.createRef<NativeWebViewAndroid>();
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
   getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
87
   getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
85
 
88
 
338
         key="webViewKey"
341
         key="webViewKey"
339
         {...otherProps}
342
         {...otherProps}
340
         messagingEnabled={typeof onMessage === 'function'}
343
         messagingEnabled={typeof onMessage === 'function'}
341
-        messagingModuleName={this.getMessagingModuleName()}
344
+        messagingModuleName={this.messagingModuleName}
342
         onLoadingError={this.onLoadingError}
345
         onLoadingError={this.onLoadingError}
343
         onLoadingFinish={this.onLoadingFinish}
346
         onLoadingFinish={this.onLoadingFinish}
344
         onLoadingProgress={this.onLoadingProgress}
347
         onLoadingProgress={this.onLoadingProgress}