improve speed and fixed one bug which cause crash after unmount component

This commit is contained in:
Ali Najafizadeh
2015-08-04 15:01:37 -04:00
parent 4b7aa937f6
commit 2adc4e4fa4
2 changed files with 15 additions and 7 deletions
+14 -6
View File
@@ -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
View File
@@ -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": {