From 2adc4e4fa417459f152eb679e21caeef92a59a97 Mon Sep 17 00:00:00 2001 From: Ali Najafizadeh Date: Tue, 4 Aug 2015 15:01:07 -0400 Subject: [PATCH] improve speed and fixed one bug which cause crash after unmount component --- jsx/WebViewBridge.js | 20 ++++++++++++++------ package.json | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/jsx/WebViewBridge.js b/jsx/WebViewBridge.js index b7df6f5..4984cb3 100644 --- a/jsx/WebViewBridge.js +++ b/jsx/WebViewBridge.js @@ -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; }); } } diff --git a/package.json b/package.json index dcf2137..5fda936 100644 --- a/package.json +++ b/package.json @@ -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": {