diff --git a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java index e9111bee..1189811c 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -43,8 +43,10 @@ import pub.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; +import com.github.pengfeizhou.jscore.JavaValue; import java.util.HashMap; import java.util.LinkedList; @@ -641,6 +643,14 @@ public abstract class ViewNode extends DoricContextHolder { return getNodeView().getPivotY() / getNodeView().getHeight(); } + private String[] animatedKeys = { + "translationX", + "translationY", + "scaleX", + "scaleY", + "rotation", + }; + @DoricMethod public void doAnimation(JSValue value, final DoricPromise promise) { Animator animator = parseAnimator(value); @@ -649,7 +659,11 @@ public abstract class ViewNode extends DoricContextHolder { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); - promise.resolve(); + JSONBuilder jsonBuilder = new JSONBuilder(); + for (String key : animatedKeys) { + jsonBuilder.put(key, getAnimatedValue(key)); + } + promise.resolve(new JavaValue(jsonBuilder.toJSONObject())); } }); animator.start(); @@ -673,37 +687,6 @@ public abstract class ViewNode extends DoricContextHolder { if (delayJS.isNumber()) { animatorSet.setStartDelay(delayJS.asNumber().toLong()); } - JSValue fillModeJSVal = value.asObject().getProperty("fillMode"); - final int fillMode = fillModeJSVal.asNumber().toInt(); - - animatorSet.addListener(new AnimatorListenerAdapter() { - private HashMap originVals = new HashMap<>(); - private String[] keys = { - "translationX", - "translationY", - "scaleX", - "scaleY", - "rotation", - }; - - @Override - public void onAnimationStart(Animator animation) { - super.onAnimationStart(animation); - for (String key : keys) { - originVals.put(key, getAnimatedValue(key)); - } - } - - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - if ((fillMode & 1) != 1) { - for (String key : keys) { - setAnimatedValue(key, originVals.get(key)); - } - } - } - }); return animatorSet; } else if (value.isObject()) { JSArray changeables = value.asObject().getProperty("changeables").asArray(); diff --git a/demo/src/ComplicatedAnimations.ts b/demo/src/ComplicatedAnimations.ts index 8f4d0e26..9b11d028 100644 --- a/demo/src/ComplicatedAnimations.ts +++ b/demo/src/ComplicatedAnimations.ts @@ -24,6 +24,35 @@ class AnimationDemo extends Panel { title("Complicated Animation"), vlayout( [ + hlayout([ + thisLabel('reset').apply({ + onClick: () => { + const rotation = new RotationAnimation + rotation.duration = 1000 + rotation.fromRotation = view.rotation || 0 + rotation.toRotation = 0 + const translation = new TranslationAnimation + translation.duration = 1000 + translation.fromTranslationX = view.translationX || 0 + translation.toTranslationX = 0 + translation.fromTranslationY = view.translationY || 0 + translation.toTranslationY = 0 + const scale = new ScaleAnimation + scale.duration = 1000 + scale.fromScaleX = view.scaleX || 1 + scale.toScaleX = 1 + scale.fromScaleY = view.scaleY || 1 + scale.toScaleY = 1 + const animationSet = new AnimationSet + animationSet.addAnimation(rotation) + animationSet.addAnimation(translation) + animationSet.addAnimation(scale) + view.doAnimation(context, animationSet).then(() => { + modal(context).toast('Resetd') + }) + } + }), + ]).apply({ space: 10 } as IHLayout), hlayout([ thisLabel('TranslationX').apply({ onClick: () => { @@ -51,8 +80,8 @@ class AnimationDemo extends Panel { onClick: () => { const animation = new ScaleAnimation animation.duration = 1000 - animation.fromScaleX = 0 - animation.toScaleX = 5 + animation.fromScaleX = view.scaleX || 1 + animation.toScaleX = animation.fromScaleX + 1 view.doAnimation(context, animation) } }), @@ -60,8 +89,8 @@ class AnimationDemo extends Panel { onClick: () => { const animation = new ScaleAnimation animation.duration = 1000 - animation.fromScaleY = 0 - animation.toScaleY = 5 + animation.fromScaleY = view.scaleY || 1 + animation.toScaleY = animation.fromScaleY + 1 view.doAnimation(context, animation) } }), @@ -69,8 +98,8 @@ class AnimationDemo extends Panel { onClick: () => { const animation = new RotationAnimation animation.duration = 1000 - animation.fromRotation = 0 - animation.toRotation = 4 + animation.fromRotation = view.rotation || 0 + animation.toRotation = animation.fromRotation + 0.25 view.doAnimation(context, animation) } }),