feat:android add transformation properties

This commit is contained in:
pengfei.zhou 2019-11-29 18:23:33 +08:00
parent 8b22f3e362
commit f5f157a0b6
2 changed files with 241 additions and 24 deletions

View File

@ -28,6 +28,7 @@ import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricRegistry;
import pub.doric.async.AsyncResult;
@ -184,17 +185,6 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
setBgColor(prop.asNumber().toInt());
}
break;
case "rotation":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getRotation(),
prop.asNumber().toFloat()));
} else {
setRotation(prop.asNumber().toFloat());
}
break;
case "onClick":
final String functionId = prop.asString().value();
view.setOnClickListener(new View.OnClickListener() {
@ -248,6 +238,103 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
);
}
break;
case "translationX":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getTranslationX(),
prop.asNumber().toFloat()));
} else {
setTranslationX(prop.asNumber().toFloat());
}
break;
case "translationY":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getTranslationY(),
prop.asNumber().toFloat()));
} else {
setTranslationY(prop.asNumber().toFloat());
}
break;
case "scaleX":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getScaleX(),
prop.asNumber().toFloat()));
} else {
setScaleX(prop.asNumber().toFloat());
}
case "scaleY":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getScaleY(),
prop.asNumber().toFloat()));
} else {
setScaleY(prop.asNumber().toFloat());
}
case "pivotX":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getPivotX(),
prop.asNumber().toFloat()));
} else {
setPivotX(prop.asNumber().toFloat());
}
break;
case "pivotY":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getPivotY(),
prop.asNumber().toFloat()));
} else {
setPivotY(prop.asNumber().toFloat());
}
break;
case "rotation":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getRotation(),
prop.asNumber().toFloat()));
} else {
setRotation(prop.asNumber().toFloat());
}
break;
case "rotationX":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getRotationX(),
prop.asNumber().toFloat()));
} else {
setRotationX(prop.asNumber().toFloat());
}
break;
case "rotationY":
if (isAnimating()) {
addAnimator(ObjectAnimator.ofFloat(
this,
name,
getRotationY(),
prop.asNumber().toFloat()));
} else {
setRotationY(prop.asNumber().toFloat());
}
break;
default:
break;
}
@ -392,16 +479,6 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
return DoricUtils.px2dp(getNodeView().getHeight());
}
@DoricMethod
public void setRotation(float rotation) {
getNodeView().setRotation(rotation * 180);
}
@DoricMethod
public float getRotation() {
return getNodeView().getRotation() / 180;
}
@DoricMethod
protected void setWidth(float width) {
if (mLayoutParams.width >= 0) {
@ -473,4 +550,94 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
public float getCorners() {
return DoricUtils.px2dp((int) requireDoricLayer().getCornerRadius());
}
@DoricMethod
public void setTranslationX(float v) {
getNodeView().setTranslationX(DoricUtils.dp2px(v));
}
@DoricMethod
public float getTranslationX() {
return DoricUtils.px2dp((int) getNodeView().getTranslationX());
}
@DoricMethod
public void setTranslationY(float v) {
getNodeView().setTranslationY(DoricUtils.dp2px(v));
}
@DoricMethod
public float getTranslationY() {
return DoricUtils.px2dp((int) getNodeView().getTranslationY());
}
@DoricMethod
public void setScaleX(float v) {
getNodeView().setScaleX(v);
}
@DoricMethod
public float getScaleX() {
return getNodeView().getScaleX();
}
@DoricMethod
public void setScaleY(float v) {
getNodeView().setScaleY(v);
}
@DoricMethod
public float getScaleY() {
return getNodeView().getScaleY();
}
@DoricMethod
public void setRotation(float rotation) {
getNodeView().setRotation(rotation * 180);
}
@DoricMethod
public float getRotation() {
return getNodeView().getRotation() / 180;
}
@DoricMethod
public void setRotationX(float rotation) {
getNodeView().setRotationX(rotation * 180);
}
@DoricMethod
public float getRotationX() {
return getNodeView().getRotationX() / 180;
}
@DoricMethod
public void setRotationY(float rotation) {
getNodeView().setRotationY(rotation * 180);
}
@DoricMethod
public float getRotationY() {
return getNodeView().getRotationY() / 180;
}
@DoricMethod
public void setPivotX(float v) {
getNodeView().setPivotX(v * getNodeView().getWidth());
}
@DoricMethod
public float getPivotX() {
return getNodeView().getPivotX() / getNodeView().getWidth();
}
@DoricMethod
public void setPivotY(float v) {
getNodeView().setPivotY(v * getNodeView().getHeight());
}
@DoricMethod
public float getPivotY() {
return getNodeView().getPivotY() / getNodeView().getHeight();
}
}

View File

@ -42,6 +42,30 @@ export interface IView {
layoutConfig?: LayoutConfig
onClick?: Function
identifier?: string
/**++++++++++transform++++++++++*/
translationX?: number
translationY?: number
scaleX?: number
scaleY?: number
/**
* float [0,..1]
*/
pivotX?: number
/**
* float [0,..1]
*/
pivotY?: number
rotation?: number
rotationX?: number
rotationY?: number
/**----------transform----------*/
}
@ -61,9 +85,6 @@ export abstract class View implements Modeling, IView {
@Property
bgColor?: Color | GradientColor
@Property
rotation?: number
@Property
corners?: number | { leftTop?: number; rightTop?: number; leftBottom?: number; rightBottom?: number }
@ -288,6 +309,35 @@ export abstract class View implements Modeling, IView {
getRotation(context: BridgeContext) {
return this.nativeChannel(context, 'getRotation')() as Promise<number>
}
/**++++++++++transform++++++++++*/
@Property
translationX?: number
@Property
translationY?: number
@Property
scaleX?: number
@Property
scaleY?: number
@Property
pivotX?: number
@Property
pivotY?: number
@Property
rotation?: number
@Property
rotationX?: number
@Property
rotationY?: number
/**----------transform----------*/
}
export abstract class Superview extends View {