Skip to content

Commit

Permalink
fix(Android): Resolve crypto error with uuid usage (react-native-webv…
Browse files Browse the repository at this point in the history
…iew#1334)

* fix(Android): uuid generation issue

* chore: remove redundant types/uuid dependency

* refactor(Android): replace uuid function with unique instance counter
  • Loading branch information
artyorsh authored Apr 21, 2020
1 parent c6a39e9 commit 438e292
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
},
"dependencies": {
"escape-string-regexp": "2.0.0",
"invariant": "2.2.4",
"uuid": "^7.0.3"
"invariant": "2.2.4"
},
"devDependencies": {
"@babel/core": "7.4.5",
Expand All @@ -48,7 +47,6 @@
"@types/jest": "24.0.18",
"@types/react": "16.8.8",
"@types/react-native": "0.60.11",
"@types/uuid": "^7.0.2",
"@typescript-eslint/eslint-plugin": "2.1.0",
"@typescript-eslint/parser": "2.1.0",
"babel-eslint": "10.0.3",
Expand Down
17 changes: 10 additions & 7 deletions src/WebView.android.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { v4 as uuid } from 'uuid';

import {
Image,
Expand Down Expand Up @@ -42,6 +41,11 @@ const RNCWebView = requireNativeComponent(
) as typeof NativeWebViewAndroid;
const { resolveAssetSource } = Image;

/**
* A simple counter to uniquely identify WebView instances. Do not use this for anything else.
*/
let uniqueRef = 0;

/**
* Renders a native WebView.
*/
Expand Down Expand Up @@ -71,15 +75,14 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
lastErrorEvent: null,
};

uniqueRef = uuid().replace(/-/g, '');

webViewRef = React.createRef<NativeWebViewAndroid>();

componentDidMount = () => {
BatchedBridge.registerCallableModule(this.getMessagingModuleName(), this);
}
messagingModuleName = `WebViewMessageHandler${uniqueRef+=1}`;

getMessagingModuleName = () => `WebViewMessageHandler${this.uniqueRef}`;
componentDidMount = () => {
BatchedBridge.registerCallableModule(this.messagingModuleName, this);
};

getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;

Expand Down Expand Up @@ -338,7 +341,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
key="webViewKey"
{...otherProps}
messagingEnabled={typeof onMessage === 'function'}
messagingModuleName={this.getMessagingModuleName()}
messagingModuleName={this.messagingModuleName}
onLoadingError={this.onLoadingError}
onLoadingFinish={this.onLoadingFinish}
onLoadingProgress={this.onLoadingProgress}
Expand Down

0 comments on commit 438e292

Please sign in to comment.