You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2019/04/01 13:03:28 UTC

[incubator-weex] branch master updated: [Android] Fix blank page when JS exception raised before batch end. (#2254)

This is an automated email from the ASF dual-hosted git repository.

kyork pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 0793e17  [Android] Fix blank page when JS exception raised before batch end. (#2254)
0793e17 is described below

commit 0793e1782da1ef3d3b42f1d265294181b3e65106
Author: sunshl <su...@gmail.com>
AuthorDate: Mon Apr 1 21:03:22 2019 +0800

    [Android] Fix blank page when JS exception raised before batch end. (#2254)
    
    * issue: https://github.com/apache/incubator-weex/issues/2253
    
    If more than two pages exist and mCurrentBatchInstanceId not matches new instanceId, we will post all stashed actions at once.
    That will cause losing efficacy of batch action, but it is acceptable because it's not serious problem.
---
 .../java/com/taobao/weex/ui/WXRenderManager.java   | 41 +++++++++++++++++++---
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java b/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java
index ac02fa8..928c491 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java
@@ -49,6 +49,7 @@ public class WXRenderManager {
 
   private volatile ConcurrentHashMap<String, RenderContextImpl> mRenderContext;
   private WXRenderHandler mWXRenderHandler;
+  private String mCurrentBatchInstanceId = null;
   private ArrayList<Map<String,Object>> mBatchActions = new ArrayList<>();
   private final int MAX_DROP_FRAME_NATIVE_BATCH = 2000;
   private final static  String sKeyAction = "Action";
@@ -123,18 +124,38 @@ public class WXRenderManager {
   }
 
   private void postAllStashedGraphicAction(final String instanceId,final BasicGraphicAction action) {
-      ArrayList<Map<String, Object>> tmpList = new ArrayList<>(mBatchActions);
+      final RenderContextImpl renderContext = mRenderContext.get(instanceId);
+
+      /// keep actions if renderContext still exist
+      ArrayList<Map<String, Object>> tmpList = null;
+      if (renderContext != null) {
+        tmpList = new ArrayList<>(mBatchActions);
+      }
+
+      // clear stashed actions
       this.mBatchActions.clear();
+      mCurrentBatchInstanceId = null;
+      nativeBatchTimes = 0;
+
+      // return if renderContext has been destroyed
+      if (renderContext == null) {
+        return;
+      }
+
+      /// post actions if renderContext still exist
       ArrayList<BasicGraphicAction> actions = new ArrayList<>(tmpList.size());
       for (int i = 0 ; i < tmpList.size(); i ++) {
           Map<String, Object> item = tmpList.get(i);
-          BasicGraphicAction tmpAction = (BasicGraphicAction)item.get(sKeyAction);
+          Object mustBeAction = item.get(sKeyAction);
+          if (!(mustBeAction instanceof BasicGraphicAction)) {
+            continue;
+          }
+          BasicGraphicAction tmpAction = (BasicGraphicAction)mustBeAction;
           if (tmpAction.mActionType == BasicGraphicAction.ActionTypeBatchBegin || tmpAction.mActionType == BasicGraphicAction.ActionTypeBatchEnd) {
-              continue;
+            continue;
           }
           actions.add(tmpAction);
       }
-      nativeBatchTimes = 0;
       postGraphicAction(instanceId, new GraphicActionBatchAction(action.getWXSDKIntance(),action.getRef(), actions));
   }
 
@@ -144,6 +165,17 @@ public class WXRenderManager {
       return;
     }
 
+    // If more than two pages exist and mCurrentBatchInstanceId not matches new instanceId, we will post all stashed actions at once.
+    // That will cause losing efficacy of batch action, but it is acceptable because it's not serious problem.
+    if (mCurrentBatchInstanceId != null && instanceId != null && !mCurrentBatchInstanceId.equals(instanceId) && mBatchActions.size() > 0) {
+      Map<String, Object> lastItem = mBatchActions.get(mBatchActions.size() - 1);
+      Object mustBeAction = lastItem.get(sKeyAction);
+      if (mustBeAction instanceof BasicGraphicAction) {
+        BasicGraphicAction lastAction = (BasicGraphicAction)mustBeAction;
+        postAllStashedGraphicAction(mCurrentBatchInstanceId, lastAction);
+      }
+    }
+
     if (action.mActionType == BasicGraphicAction.ActionTypeBatchEnd) {
         postAllStashedGraphicAction(instanceId,action);
         return;
@@ -155,6 +187,7 @@ public class WXRenderManager {
             HashMap<String, Object> item = new HashMap<>(1);
             item.put(sKeyAction, action);
             mBatchActions.add(item);
+            mCurrentBatchInstanceId = instanceId;
             return;
         }
     }