From 41b74312cbe1dcbe7c840db8e51afc0cbdba312f Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 28 Dec 2021 16:30:41 +0800 Subject: [PATCH] android: fix cannot set Pivot before view is layouted --- .../src/main/java/pub/doric/DoricContext.java | 1 - .../main/java/pub/doric/shader/ViewNode.java | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContext.java b/doric-android/doric/src/main/java/pub/doric/DoricContext.java index 33f36474..17dc4edb 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -35,7 +35,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.WeakHashMap; import java.util.concurrent.Callable; import pub.doric.async.AsyncResult; diff --git a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java index 0806eed2..e417d842 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -53,7 +53,6 @@ import com.github.pengfeizhou.jscore.JavaValue; import org.json.JSONObject; import java.util.LinkedList; -import java.util.WeakHashMap; import pub.doric.DoricContext; import pub.doric.DoricRegistry; @@ -80,6 +79,8 @@ public abstract class ViewNode extends DoricContextHolder { protected ViewGroup.LayoutParams mLayoutParams; private String mType; protected JSObject mFlexConfig; + private Float mPivotX = null; + private Float mPivotY = null; public JSObject getFlexConfig() { return mFlexConfig; @@ -881,6 +882,12 @@ public abstract class ViewNode extends DoricContextHolder { @DoricMethod public void setRotation(float rotation) { + if (mPivotX != null) { + setPivotX(mPivotX); + } + if (mPivotY != null) { + setPivotY(mPivotY); + } getNodeView().setRotation(rotation * 180); } @@ -911,6 +918,7 @@ public abstract class ViewNode extends DoricContextHolder { @DoricMethod public void setPivotX(float v) { + mPivotX = v; getNodeView().setPivotX(v * getNodeView().getWidth()); } @@ -921,6 +929,7 @@ public abstract class ViewNode extends DoricContextHolder { @DoricMethod public void setPivotY(float v) { + mPivotY = v; getNodeView().setPivotY(v * getNodeView().getHeight()); } @@ -1207,6 +1216,12 @@ public abstract class ViewNode extends DoricContextHolder { setRotation(0); setRotationX(0); setRotationY(0); + if (mPivotX != null) { + mPivotX = 0.5f; + } + if (mPivotY != null) { + mPivotY = 0.5f; + } mView.setPadding(0, 0, 0, 0); if (mView.hasOnClickListeners()) { mView.setOnClickListener(null);