From 50402e20b1afddaccd74cc61b75786f8533e3371 Mon Sep 17 00:00:00 2001 From: vakrilov Date: Thu, 26 Nov 2015 16:57:38 +0200 Subject: [PATCH] FIX: Set both translate and scale values after animation end --- apps/tests/testRunner.ts | 6 +- apps/tests/ui/animation/animation-tests.ts | 80 +++++++++++----------- ui/animation/animation.android.ts | 53 +++++++++----- 3 files changed, 77 insertions(+), 62 deletions(-) diff --git a/apps/tests/testRunner.ts b/apps/tests/testRunner.ts index 4d5c0634b..7353c6b0d 100644 --- a/apps/tests/testRunner.ts +++ b/apps/tests/testRunner.ts @@ -83,9 +83,9 @@ allTests["REPEATER"] = require("./ui/repeater/repeater-tests"); allTests["SEARCH-BAR"] = require('./ui/search-bar/search-bar-tests'); allTests["CONNECTIVITY"] = require("./connectivity-tests"); allTests["SEGMENTED-BAR"] = require("./ui/segmented-bar/segmented-bar-tests"); +allTests["ANIMATION"] = require("./ui/animation/animation-tests"); if (!isRunningOnEmulator()) { - allTests["ANIMATION"] = require("./ui/animation/animation-tests"); allTests["LOCATION"] = require("./location-tests"); } @@ -140,7 +140,7 @@ function startLog(): void { function log(): void { let testsName: string = this.name; let duration = TKUnit.time() - this.start; - TKUnit.write(testsName + " COMPLETED for " + duration, messageType.info); + TKUnit.write(testsName + " COMPLETED for " + duration + " BACKSTACK DEPTH: " + topmost().backStack.length, messageType.info); } export var runAll = function (moduleName?: string) { @@ -161,7 +161,7 @@ export var runAll = function (moduleName?: string) { var test = testModule.createTestCase ? testModule.createTestCase() : testModule; test.name = name; - + testsQueue.push(new TestInfo(startLog, test)); diff --git a/apps/tests/ui/animation/animation-tests.ts b/apps/tests/ui/animation/animation-tests.ts index 6f205f85f..cdde6ad96 100644 --- a/apps/tests/ui/animation/animation-tests.ts +++ b/apps/tests/ui/animation/animation-tests.ts @@ -269,7 +269,7 @@ export var test_AnimateOpacity = function (done) { label.animate({ opacity: 0.75 }) .then(() => { - TKUnit.assert(label.opacity === 0.75); + TKUnit.assertEqual(label.opacity, 0.75, "label.opacity"); helper.goBack(); done(); }) @@ -326,8 +326,8 @@ export var test_AnimateTranslate = function (done) { label.animate({ translate: { x: 100, y: 200 } }) .then(() => { - TKUnit.assert(label.translateX === 100); - TKUnit.assert(label.translateY === 200); + TKUnit.assertEqual(label.translateX, 100, "label.translateX"); + TKUnit.assertEqual(label.translateY, 200, "label.translateY"); assertIOSNativeTransformIsCorrect(label); helper.goBack(); done(); @@ -356,8 +356,8 @@ export var test_AnimateScale = function (done) { label.animate({ scale: { x: 2, y: 3 } }) .then(() => { - TKUnit.assert(label.scaleX === 2); - TKUnit.assert(label.scaleY === 3); + TKUnit.assertEqual(label.scaleX, 2,"label.scaleX"); + TKUnit.assertEqual(label.scaleY, 3,"label.scaleY"); assertIOSNativeTransformIsCorrect(label); helper.goBack(); done(); @@ -386,7 +386,7 @@ export var test_AnimateRotate = function (done) { label.animate({ rotate: 123 }) .then(() => { - TKUnit.assert(label.rotate === 123); + TKUnit.assertEqual(label.rotate, 123, "label.rotate"); assertIOSNativeTransformIsCorrect(label); helper.goBack(); done(); @@ -419,11 +419,11 @@ export var test_AnimateTranslateScaleAndRotateSimultaneously = function (done) { rotate: 123 }) .then(() => { - TKUnit.assert(label.translateX === 100); - TKUnit.assert(label.translateY === 200); - TKUnit.assert(label.scaleX === 2); - TKUnit.assert(label.scaleY === 3); - TKUnit.assert(label.rotate === 123); + TKUnit.assertEqual(label.translateX, 100, "label.translateX"); + TKUnit.assertEqual(label.translateY, 200, "label.translateY"); + TKUnit.assertEqual(label.scaleX, 2, "label.scaleX"); + TKUnit.assertEqual(label.scaleY, 3, "label.scaleY"); + TKUnit.assertEqual(label.rotate, 123, "label.rotate"); assertIOSNativeTransformIsCorrect(label); helper.goBack(); done(); @@ -450,35 +450,35 @@ export var test_AnimateTranslateScaleAndRotateSequentially = function (done) { helper.navigate(pageFactory); TKUnit.waitUntilReady(() => { return label.isLoaded }); - label.animate({translate: { x: 100, y: 200 }}) - .then(() => { - TKUnit.assert(label.translateX === 100); - TKUnit.assert(label.translateY === 200); - assertIOSNativeTransformIsCorrect(label); - return label.animate({ scale: { x: 2, y: 3 } }); - }) - .then(() => { - TKUnit.assert(label.translateX === 100); - TKUnit.assert(label.translateY === 200); - TKUnit.assert(label.scaleX === 2); - TKUnit.assert(label.scaleY === 3); - assertIOSNativeTransformIsCorrect(label); - return label.animate({ rotate: 123 }); - }) - .then(() => { - TKUnit.assert(label.translateX === 100); - TKUnit.assert(label.translateY === 200); - TKUnit.assert(label.scaleX === 2); - TKUnit.assert(label.scaleY === 3); - TKUnit.assert(label.rotate === 123); - assertIOSNativeTransformIsCorrect(label); - helper.goBack(); - done(); - }) - .catch((e) => { - helper.goBack(); - done(e); - }); + label.animate({ translate: { x: 100, y: 200 } }) + .then(() => { + TKUnit.assertEqual(label.translateX, 100, "label.translateX"); + TKUnit.assertEqual(label.translateY, 200, "label.translateY"); + assertIOSNativeTransformIsCorrect(label); + return label.animate({ scale: { x: 2, y: 3 } }); + }) + .then(() => { + TKUnit.assertEqual(label.translateX, 100, "label.translateX"); + TKUnit.assertEqual(label.translateY, 200, "label.translateY"); + TKUnit.assertEqual(label.scaleX, 2, "label.scaleX"); + TKUnit.assertEqual(label.scaleY, 3, "label.scaleY"); + assertIOSNativeTransformIsCorrect(label); + return label.animate({ rotate: 123 }); + }) + .then(() => { + TKUnit.assertEqual(label.translateX, 100, "label.translateX"); + TKUnit.assertEqual(label.translateY, 200, "label.translateY"); + TKUnit.assertEqual(label.scaleX, 2, "label.scaleX"); + TKUnit.assertEqual(label.scaleY, 3, "label.scaleY"); + TKUnit.assertEqual(label.rotate, 123, "label.rotate"); + assertIOSNativeTransformIsCorrect(label); + helper.goBack(); + done(); + }) + .catch((e) => { + helper.goBack(); + done(e); + }); } export var test_AnimationsAreAlwaysPlayed = function (done) { diff --git a/ui/animation/animation.android.ts b/ui/animation/animation.android.ts index ee0832269..bcb0702f2 100644 --- a/ui/animation/animation.android.ts +++ b/ui/animation/animation.android.ts @@ -136,7 +136,8 @@ export class Animation extends common.Animation implements definition.Animation var animators = new Array(); var propertyUpdateCallbacks = new Array(); var propertyResetCallbacks = new Array(); - var originalValue; + var originalValue1; + var originalValue2; var density = utils.layout.getDisplayDensity(); var xyObjectAnimators: any; var animatorSet: android.animation.AnimatorSet; @@ -157,16 +158,16 @@ export class Animation extends common.Animation implements definition.Animation switch (propertyAnimation.property) { case common.Properties.opacity: - originalValue = nativeView.getAlpha(); + originalValue1 = nativeView.getAlpha(); nativeArray = java.lang.reflect.Array.newInstance(floatType, 1); nativeArray[0] = propertyAnimation.value; propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.opacity = propertyAnimation.value })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setAlpha(originalValue); })); + propertyResetCallbacks.push(checkAnimation(() => { nativeView.setAlpha(originalValue1); })); animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "alpha", nativeArray)); break; case common.Properties.backgroundColor: - originalValue = nativeView.getBackground(); + originalValue1 = nativeView.getBackground(); nativeArray = java.lang.reflect.Array.newInstance(java.lang.Object.class, 2); nativeArray[0] = propertyAnimation.target.backgroundColor ? java.lang.Integer.valueOf((propertyAnimation.target.backgroundColor).argb) : java.lang.Integer.valueOf(-1); nativeArray[1] = java.lang.Integer.valueOf((propertyAnimation.value).argb); @@ -179,28 +180,35 @@ export class Animation extends common.Animation implements definition.Animation })); propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.backgroundColor = propertyAnimation.value; })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setBackground(originalValue); })); + propertyResetCallbacks.push(checkAnimation(() => { nativeView.setBackground(originalValue1); })); animators.push(animator); break; case common.Properties.translate: xyObjectAnimators = java.lang.reflect.Array.newInstance(android.animation.Animator.class, 2); - originalValue = nativeView.getTranslationX(); nativeArray = java.lang.reflect.Array.newInstance(floatType, 1); nativeArray[0] = propertyAnimation.value.x * density; xyObjectAnimators[0] = android.animation.ObjectAnimator.ofFloat(nativeView, "translationX", nativeArray); xyObjectAnimators[0].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations)); - propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.translateX = propertyAnimation.value.x; })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setTranslationX(originalValue); })); - originalValue = nativeView.getTranslationY(); nativeArray = java.lang.reflect.Array.newInstance(floatType, 1); nativeArray[0] = propertyAnimation.value.y * density; xyObjectAnimators[1] = android.animation.ObjectAnimator.ofFloat(nativeView, "translationY", nativeArray); xyObjectAnimators[1].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations)); - propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.translateY = propertyAnimation.value.y; })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setTranslationY(originalValue); })); + + originalValue1 = nativeView.getTranslationX(); + originalValue2 = nativeView.getTranslationY(); + + propertyUpdateCallbacks.push(checkAnimation(() => { + propertyAnimation.target.translateX = propertyAnimation.value.x; + propertyAnimation.target.translateY = propertyAnimation.value.y; + })); + + propertyResetCallbacks.push(checkAnimation(() => { + nativeView.setTranslationX(originalValue1); + nativeView.setTranslationY(originalValue2); + })); animatorSet = new android.animation.AnimatorSet(); animatorSet.playTogether(xyObjectAnimators); @@ -211,21 +219,28 @@ export class Animation extends common.Animation implements definition.Animation case common.Properties.scale: xyObjectAnimators = java.lang.reflect.Array.newInstance(android.animation.Animator.class, 2); - originalValue = nativeView.getScaleX(); nativeArray = java.lang.reflect.Array.newInstance(floatType, 1); nativeArray[0] = propertyAnimation.value.x; xyObjectAnimators[0] = android.animation.ObjectAnimator.ofFloat(nativeView, "scaleX", nativeArray); xyObjectAnimators[0].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations)); - propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.scaleX = propertyAnimation.value.x; })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setScaleX(originalValue); })); - originalValue = nativeView.getScaleY(); nativeArray = java.lang.reflect.Array.newInstance(floatType, 1); nativeArray[0] = propertyAnimation.value.y; xyObjectAnimators[1] = android.animation.ObjectAnimator.ofFloat(nativeView, "scaleY", nativeArray); xyObjectAnimators[1].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations)); - propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.scaleY = propertyAnimation.value.y; })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setScaleY(originalValue); })); + + originalValue1 = nativeView.getScaleX(); + originalValue2 = nativeView.getScaleY(); + + propertyUpdateCallbacks.push(checkAnimation(() => { + propertyAnimation.target.scaleX = propertyAnimation.value.x; + propertyAnimation.target.scaleY = propertyAnimation.value.y; + })); + + propertyResetCallbacks.push(checkAnimation(() => { + nativeView.setScaleY(originalValue1); + nativeView.setScaleY(originalValue2); + })); animatorSet = new android.animation.AnimatorSet(); animatorSet.playTogether(xyObjectAnimators); @@ -234,11 +249,11 @@ export class Animation extends common.Animation implements definition.Animation break; case common.Properties.rotate: - originalValue = nativeView.getRotation(); + originalValue1 = nativeView.getRotation(); nativeArray = java.lang.reflect.Array.newInstance(floatType, 1); nativeArray[0] = propertyAnimation.value; propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.rotate = propertyAnimation.value; })); - propertyResetCallbacks.push(checkAnimation(() => { nativeView.setRotation(originalValue); })); + propertyResetCallbacks.push(checkAnimation(() => { nativeView.setRotation(originalValue1); })); animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "rotation", nativeArray)); break;