mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
FIX: Set both translate and scale values after animation end
This commit is contained in:
@ -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) {
|
||||
|
@ -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();
|
||||
@ -452,25 +452,25 @@ export var test_AnimateTranslateScaleAndRotateSequentially = 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);
|
||||
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);
|
||||
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.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();
|
||||
|
@ -136,7 +136,8 @@ export class Animation extends common.Animation implements definition.Animation
|
||||
var animators = new Array<android.animation.Animator>();
|
||||
var propertyUpdateCallbacks = new Array<Function>();
|
||||
var propertyResetCallbacks = new Array<Function>();
|
||||
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((<color.Color>propertyAnimation.target.backgroundColor).argb) : java.lang.Integer.valueOf(-1);
|
||||
nativeArray[1] = java.lang.Integer.valueOf((<color.Color>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;
|
||||
|
||||
|
Reference in New Issue
Block a user