* [Core] Update textContentBoxMeasurement to avoid crash

Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/16d4eb89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/16d4eb89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/16d4eb89

Branch: refs/heads/master
Commit: 16d4eb896f9d61375fedb78804447d32a75d14b1
Parents: 3f29907
Author: YorkShen <shenyua...@gmail.com>
Authored: Sat Apr 28 15:32:25 2018 +0800
Committer: YorkShen <shenyua...@gmail.com>
Committed: Mon May 7 15:52:08 2018 +0800

----------------------------------------------------------------------
 .../measurefunc/TextContentBoxMeasurement.java  | 44 +++++++++++---------
 .../com/taobao/weex/ui/WXRenderManager.java     |  6 +++
 2 files changed, 30 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/16d4eb89/android/sdk/src/main/java/com/taobao/weex/layout/measurefunc/TextContentBoxMeasurement.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/layout/measurefunc/TextContentBoxMeasurement.java
 
b/android/sdk/src/main/java/com/taobao/weex/layout/measurefunc/TextContentBoxMeasurement.java
index 2a5ba3f..1f7789c 100644
--- 
a/android/sdk/src/main/java/com/taobao/weex/layout/measurefunc/TextContentBoxMeasurement.java
+++ 
b/android/sdk/src/main/java/com/taobao/weex/layout/measurefunc/TextContentBoxMeasurement.java
@@ -37,6 +37,7 @@ import android.text.style.AbsoluteSizeSpan;
 import android.text.style.AlignmentSpan;
 import android.text.style.ForegroundColorSpan;
 
+import com.taobao.weex.WXSDKManager;
 import com.taobao.weex.common.Constants;
 import com.taobao.weex.dom.TextDecorationSpan;
 import com.taobao.weex.dom.WXAttr;
@@ -167,30 +168,33 @@ public class TextContentBoxMeasurement extends 
ContentBoxMeasurement {
    **/
   @Override
   public void layoutAfter(float computedWidth, float computedHeight) {
-    if (hasBeenMeasured) {
-      if (layout != null &&
-              WXDomUtils.getContentWidth(mComponent.getPadding(), 
mComponent.getBorder(), computedWidth)
-                      != previousWidth) {
+    if(mComponent!=null) {
+      if (hasBeenMeasured) {
+        if (layout != null &&
+            WXDomUtils
+                .getContentWidth(mComponent.getPadding(), 
mComponent.getBorder(), computedWidth)
+                != previousWidth) {
+          recalculateLayout(computedWidth);
+        }
+      } else {
+        updateStyleAndText();
         recalculateLayout(computedWidth);
       }
-    } else {
-      updateStyleAndText();
-      recalculateLayout(computedWidth);
-    }
-    hasBeenMeasured = false;
-    if (layout != null && !layout.equals(atomicReference.get()) &&
-            Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
-      if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
-        warmUpTextLayoutCache(layout);
+      hasBeenMeasured = false;
+      if (layout != null && !layout.equals(atomicReference.get()) &&
+          Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+        if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
+          warmUpTextLayoutCache(layout);
+        }
       }
+      swap();
+      WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(new 
Runnable() {
+        @Override
+        public void run() {
+          mComponent.updateExtra(atomicReference.get());
+        }
+      }, mComponent.getInstanceId());
     }
-    swap();
-    mComponent.getInstance().runOnUiThread(new Runnable() {
-      @Override
-      public void run() {
-        mComponent.updateExtra(atomicReference.get());
-      }
-    });
   }
 
   private void updateStyleAndText() {

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/16d4eb89/android/sdk/src/main/java/com/taobao/weex/ui/WXRenderManager.java
----------------------------------------------------------------------
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 e91fb08..c9b4beb 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
@@ -71,11 +71,17 @@ public class WXRenderManager {
     return statement.getWXSDKInstance();
   }
 
+  @RestrictTo(Scope.LIBRARY)
   public void postOnUiThread(Runnable runnable, long delayMillis) {
     mWXRenderHandler.postDelayed(WXThread.secure(runnable), delayMillis);
   }
 
   @RestrictTo(Scope.LIBRARY)
+  public void postOnUiThread(Runnable runnable,final String instanceId){
+    mWXRenderHandler.post(instanceId, WXThread.secure(runnable));
+  }
+
+  @RestrictTo(Scope.LIBRARY)
   public void postOnUiThread(Runnable runnable){
     mWXRenderHandler.post(WXThread.secure(runnable));
   }

Reply via email to