mirror of
https://github.com/status-im/react-native-webview-bridge.git
synced 2026-08-30 21:01:12 +00:00
improve speed and fixed one bug which cause crash after unmount component
This commit is contained in:
+14
-6
@@ -12,21 +12,28 @@ var {
|
||||
class WebViewBridge extends WebView {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handlerId = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* call the callback with handler id
|
||||
* this is a hack to make the new version working properly.
|
||||
* returns void
|
||||
*/
|
||||
getWebViewBridgeHandler(fn) {
|
||||
//this method defines in WebView component.
|
||||
//in react-native 0.6 and below, getWebWiewHandle
|
||||
//in react-native 0.7 and above getWebViewHandle
|
||||
var handler = this.getWebWiewHandle || this.getWebViewHandle;
|
||||
|
||||
setTimeout(() => {
|
||||
var handlerId = handler();
|
||||
fn(handlerId);
|
||||
}, 0);
|
||||
if (this.handlerId) {
|
||||
fn(this.handlerId);
|
||||
} else {
|
||||
// this is a hack to get the handleId correctly and
|
||||
// also avoid race condition.
|
||||
setTimeout(() => {
|
||||
this.handlerId = handler();
|
||||
fn(this.handlerId);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -85,6 +92,7 @@ class WebViewBridge extends WebView {
|
||||
//handler id
|
||||
this.getWebViewBridgeHandler((handlerId) => {
|
||||
WebViewManager.callbackCleanup(handlerId);
|
||||
this.handlerId = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-webview-bridge",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"description": "React Native WebView Javascript Bridge",
|
||||
"main": "jsx/WebViewBridge.js",
|
||||
"directories": {
|
||||
|
||||
Reference in New Issue
Block a user