android: fix cannot set Pivot before view is layouted

This commit is contained in:
pengfei.zhou 2021-12-28 16:30:41 +08:00 committed by osborn
parent 4aa1380a5a
commit 41b74312cb
2 changed files with 16 additions and 2 deletions

View File

@ -35,7 +35,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import pub.doric.async.AsyncResult; import pub.doric.async.AsyncResult;

View File

@ -53,7 +53,6 @@ import com.github.pengfeizhou.jscore.JavaValue;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.WeakHashMap;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.DoricRegistry; import pub.doric.DoricRegistry;
@ -80,6 +79,8 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
protected ViewGroup.LayoutParams mLayoutParams; protected ViewGroup.LayoutParams mLayoutParams;
private String mType; private String mType;
protected JSObject mFlexConfig; protected JSObject mFlexConfig;
private Float mPivotX = null;
private Float mPivotY = null;
public JSObject getFlexConfig() { public JSObject getFlexConfig() {
return mFlexConfig; return mFlexConfig;
@ -881,6 +882,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
@DoricMethod @DoricMethod
public void setRotation(float rotation) { public void setRotation(float rotation) {
if (mPivotX != null) {
setPivotX(mPivotX);
}
if (mPivotY != null) {
setPivotY(mPivotY);
}
getNodeView().setRotation(rotation * 180); getNodeView().setRotation(rotation * 180);
} }
@ -911,6 +918,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
@DoricMethod @DoricMethod
public void setPivotX(float v) { public void setPivotX(float v) {
mPivotX = v;
getNodeView().setPivotX(v * getNodeView().getWidth()); getNodeView().setPivotX(v * getNodeView().getWidth());
} }
@ -921,6 +929,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
@DoricMethod @DoricMethod
public void setPivotY(float v) { public void setPivotY(float v) {
mPivotY = v;
getNodeView().setPivotY(v * getNodeView().getHeight()); getNodeView().setPivotY(v * getNodeView().getHeight());
} }
@ -1207,6 +1216,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
setRotation(0); setRotation(0);
setRotationX(0); setRotationX(0);
setRotationY(0); setRotationY(0);
if (mPivotX != null) {
mPivotX = 0.5f;
}
if (mPivotY != null) {
mPivotY = 0.5f;
}
mView.setPadding(0, 0, 0, 0); mView.setPadding(0, 0, 0, 0);
if (mView.hasOnClickListeners()) { if (mView.hasOnClickListeners()) {
mView.setOnClickListener(null); mView.setOnClickListener(null);