Browse Source

clean up code style for index.android.js

iou90 6 years ago
parent
commit
bc425f7610
1 changed files with 8 additions and 4 deletions
  1. 8
    4
      autoHeightWebView/index.android.js

+ 8
- 4
autoHeightWebView/index.android.js View File

217
     if (!e.nativeEvent) {
217
     if (!e.nativeEvent) {
218
       return;
218
       return;
219
     }
219
     }
220
-    
220
+    let data = {};
221
     // Sometimes the message is invalid JSON, so we ignore that case
221
     // Sometimes the message is invalid JSON, so we ignore that case
222
-    try { JSON.parse(isBelowKitKat ? e.nativeEvent.message : e.nativeEvent.data) } catch(e) { return }
223
-
224
-    const { height, width } = JSON.parse(isBelowKitKat ? e.nativeEvent.message : e.nativeEvent.data);
222
+    try {
223
+      data = JSON.parse(isBelowKitKat ? e.nativeEvent.message : e.nativeEvent.data);
224
+    } catch (error) {
225
+      console.error(error);
226
+      return;
227
+    }
228
+    const { height, width } = data;
225
     const { height: oldHeight, width: oldWidth } = this.state;
229
     const { height: oldHeight, width: oldWidth } = this.state;
226
     if (isSizeChanged(height, oldHeight, width, oldWidth)) {
230
     if (isSizeChanged(height, oldHeight, width, oldWidth)) {
227
       this.stopInterval();
231
       this.stopInterval();