Skip to content

Commit 50402e2

Browse files
author
vakrilov
committed
FIX: Set both translate and scale values after animation end
1 parent 755def3 commit 50402e2

File tree

3 files changed

+77
-62
lines changed

3 files changed

+77
-62
lines changed

apps/tests/testRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ allTests["REPEATER"] = require("./ui/repeater/repeater-tests");
8383
allTests["SEARCH-BAR"] = require('./ui/search-bar/search-bar-tests');
8484
allTests["CONNECTIVITY"] = require("./connectivity-tests");
8585
allTests["SEGMENTED-BAR"] = require("./ui/segmented-bar/segmented-bar-tests");
86+
allTests["ANIMATION"] = require("./ui/animation/animation-tests");
8687

8788
if (!isRunningOnEmulator()) {
88-
allTests["ANIMATION"] = require("./ui/animation/animation-tests");
8989
allTests["LOCATION"] = require("./location-tests");
9090
}
9191

@@ -140,7 +140,7 @@ function startLog(): void {
140140
function log(): void {
141141
let testsName: string = this.name;
142142
let duration = TKUnit.time() - this.start;
143-
TKUnit.write(testsName + " COMPLETED for " + duration, messageType.info);
143+
TKUnit.write(testsName + " COMPLETED for " + duration + " BACKSTACK DEPTH: " + topmost().backStack.length, messageType.info);
144144
}
145145

146146
export var runAll = function (moduleName?: string) {
@@ -161,7 +161,7 @@ export var runAll = function (moduleName?: string) {
161161

162162
var test = testModule.createTestCase ? testModule.createTestCase() : testModule;
163163
test.name = name;
164-
164+
165165

166166
testsQueue.push(new TestInfo(startLog, test));
167167

apps/tests/ui/animation/animation-tests.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export var test_AnimateOpacity = function (done) {
269269

270270
label.animate({ opacity: 0.75 })
271271
.then(() => {
272-
TKUnit.assert(label.opacity === 0.75);
272+
TKUnit.assertEqual(label.opacity, 0.75, "label.opacity");
273273
helper.goBack();
274274
done();
275275
})
@@ -326,8 +326,8 @@ export var test_AnimateTranslate = function (done) {
326326

327327
label.animate({ translate: { x: 100, y: 200 } })
328328
.then(() => {
329-
TKUnit.assert(label.translateX === 100);
330-
TKUnit.assert(label.translateY === 200);
329+
TKUnit.assertEqual(label.translateX, 100, "label.translateX");
330+
TKUnit.assertEqual(label.translateY, 200, "label.translateY");
331331
assertIOSNativeTransformIsCorrect(label);
332332
helper.goBack();
333333
done();
@@ -356,8 +356,8 @@ export var test_AnimateScale = function (done) {
356356

357357
label.animate({ scale: { x: 2, y: 3 } })
358358
.then(() => {
359-
TKUnit.assert(label.scaleX === 2);
360-
TKUnit.assert(label.scaleY === 3);
359+
TKUnit.assertEqual(label.scaleX, 2,"label.scaleX");
360+
TKUnit.assertEqual(label.scaleY, 3,"label.scaleY");
361361
assertIOSNativeTransformIsCorrect(label);
362362
helper.goBack();
363363
done();
@@ -386,7 +386,7 @@ export var test_AnimateRotate = function (done) {
386386

387387
label.animate({ rotate: 123 })
388388
.then(() => {
389-
TKUnit.assert(label.rotate === 123);
389+
TKUnit.assertEqual(label.rotate, 123, "label.rotate");
390390
assertIOSNativeTransformIsCorrect(label);
391391
helper.goBack();
392392
done();
@@ -419,11 +419,11 @@ export var test_AnimateTranslateScaleAndRotateSimultaneously = function (done) {
419419
rotate: 123
420420
})
421421
.then(() => {
422-
TKUnit.assert(label.translateX === 100);
423-
TKUnit.assert(label.translateY === 200);
424-
TKUnit.assert(label.scaleX === 2);
425-
TKUnit.assert(label.scaleY === 3);
426-
TKUnit.assert(label.rotate === 123);
422+
TKUnit.assertEqual(label.translateX, 100, "label.translateX");
423+
TKUnit.assertEqual(label.translateY, 200, "label.translateY");
424+
TKUnit.assertEqual(label.scaleX, 2, "label.scaleX");
425+
TKUnit.assertEqual(label.scaleY, 3, "label.scaleY");
426+
TKUnit.assertEqual(label.rotate, 123, "label.rotate");
427427
assertIOSNativeTransformIsCorrect(label);
428428
helper.goBack();
429429
done();
@@ -450,35 +450,35 @@ export var test_AnimateTranslateScaleAndRotateSequentially = function (done) {
450450
helper.navigate(pageFactory);
451451
TKUnit.waitUntilReady(() => { return label.isLoaded });
452452

453-
label.animate({translate: { x: 100, y: 200 }})
454-
.then(() => {
455-
TKUnit.assert(label.translateX === 100);
456-
TKUnit.assert(label.translateY === 200);
457-
assertIOSNativeTransformIsCorrect(label);
458-
return label.animate({ scale: { x: 2, y: 3 } });
459-
})
460-
.then(() => {
461-
TKUnit.assert(label.translateX === 100);
462-
TKUnit.assert(label.translateY === 200);
463-
TKUnit.assert(label.scaleX === 2);
464-
TKUnit.assert(label.scaleY === 3);
465-
assertIOSNativeTransformIsCorrect(label);
466-
return label.animate({ rotate: 123 });
467-
})
468-
.then(() => {
469-
TKUnit.assert(label.translateX === 100);
470-
TKUnit.assert(label.translateY === 200);
471-
TKUnit.assert(label.scaleX === 2);
472-
TKUnit.assert(label.scaleY === 3);
473-
TKUnit.assert(label.rotate === 123);
474-
assertIOSNativeTransformIsCorrect(label);
475-
helper.goBack();
476-
done();
477-
})
478-
.catch((e) => {
479-
helper.goBack();
480-
done(e);
481-
});
453+
label.animate({ translate: { x: 100, y: 200 } })
454+
.then(() => {
455+
TKUnit.assertEqual(label.translateX, 100, "label.translateX");
456+
TKUnit.assertEqual(label.translateY, 200, "label.translateY");
457+
assertIOSNativeTransformIsCorrect(label);
458+
return label.animate({ scale: { x: 2, y: 3 } });
459+
})
460+
.then(() => {
461+
TKUnit.assertEqual(label.translateX, 100, "label.translateX");
462+
TKUnit.assertEqual(label.translateY, 200, "label.translateY");
463+
TKUnit.assertEqual(label.scaleX, 2, "label.scaleX");
464+
TKUnit.assertEqual(label.scaleY, 3, "label.scaleY");
465+
assertIOSNativeTransformIsCorrect(label);
466+
return label.animate({ rotate: 123 });
467+
})
468+
.then(() => {
469+
TKUnit.assertEqual(label.translateX, 100, "label.translateX");
470+
TKUnit.assertEqual(label.translateY, 200, "label.translateY");
471+
TKUnit.assertEqual(label.scaleX, 2, "label.scaleX");
472+
TKUnit.assertEqual(label.scaleY, 3, "label.scaleY");
473+
TKUnit.assertEqual(label.rotate, 123, "label.rotate");
474+
assertIOSNativeTransformIsCorrect(label);
475+
helper.goBack();
476+
done();
477+
})
478+
.catch((e) => {
479+
helper.goBack();
480+
done(e);
481+
});
482482
}
483483

484484
export var test_AnimationsAreAlwaysPlayed = function (done) {

ui/animation/animation.android.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ export class Animation extends common.Animation implements definition.Animation
136136
var animators = new Array<android.animation.Animator>();
137137
var propertyUpdateCallbacks = new Array<Function>();
138138
var propertyResetCallbacks = new Array<Function>();
139-
var originalValue;
139+
var originalValue1;
140+
var originalValue2;
140141
var density = utils.layout.getDisplayDensity();
141142
var xyObjectAnimators: any;
142143
var animatorSet: android.animation.AnimatorSet;
@@ -157,16 +158,16 @@ export class Animation extends common.Animation implements definition.Animation
157158
switch (propertyAnimation.property) {
158159

159160
case common.Properties.opacity:
160-
originalValue = nativeView.getAlpha();
161+
originalValue1 = nativeView.getAlpha();
161162
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
162163
nativeArray[0] = propertyAnimation.value;
163164
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.opacity = propertyAnimation.value }));
164-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setAlpha(originalValue); }));
165+
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setAlpha(originalValue1); }));
165166
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "alpha", nativeArray));
166167
break;
167168

168169
case common.Properties.backgroundColor:
169-
originalValue = nativeView.getBackground();
170+
originalValue1 = nativeView.getBackground();
170171
nativeArray = java.lang.reflect.Array.newInstance(java.lang.Object.class, 2);
171172
nativeArray[0] = propertyAnimation.target.backgroundColor ? java.lang.Integer.valueOf((<color.Color>propertyAnimation.target.backgroundColor).argb) : java.lang.Integer.valueOf(-1);
172173
nativeArray[1] = java.lang.Integer.valueOf((<color.Color>propertyAnimation.value).argb);
@@ -179,28 +180,35 @@ export class Animation extends common.Animation implements definition.Animation
179180
}));
180181

181182
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.backgroundColor = propertyAnimation.value; }));
182-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setBackground(originalValue); }));
183+
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setBackground(originalValue1); }));
183184
animators.push(animator);
184185
break;
185186

186187
case common.Properties.translate:
187188
xyObjectAnimators = java.lang.reflect.Array.newInstance(android.animation.Animator.class, 2);
188189

189-
originalValue = nativeView.getTranslationX();
190190
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
191191
nativeArray[0] = propertyAnimation.value.x * density;
192192
xyObjectAnimators[0] = android.animation.ObjectAnimator.ofFloat(nativeView, "translationX", nativeArray);
193193
xyObjectAnimators[0].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations));
194-
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.translateX = propertyAnimation.value.x; }));
195-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setTranslationX(originalValue); }));
196194

197-
originalValue = nativeView.getTranslationY();
198195
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
199196
nativeArray[0] = propertyAnimation.value.y * density;
200197
xyObjectAnimators[1] = android.animation.ObjectAnimator.ofFloat(nativeView, "translationY", nativeArray);
201198
xyObjectAnimators[1].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations));
202-
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.translateY = propertyAnimation.value.y; }));
203-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setTranslationY(originalValue); }));
199+
200+
originalValue1 = nativeView.getTranslationX();
201+
originalValue2 = nativeView.getTranslationY();
202+
203+
propertyUpdateCallbacks.push(checkAnimation(() => {
204+
propertyAnimation.target.translateX = propertyAnimation.value.x;
205+
propertyAnimation.target.translateY = propertyAnimation.value.y;
206+
}));
207+
208+
propertyResetCallbacks.push(checkAnimation(() => {
209+
nativeView.setTranslationX(originalValue1);
210+
nativeView.setTranslationY(originalValue2);
211+
}));
204212

205213
animatorSet = new android.animation.AnimatorSet();
206214
animatorSet.playTogether(xyObjectAnimators);
@@ -211,21 +219,28 @@ export class Animation extends common.Animation implements definition.Animation
211219
case common.Properties.scale:
212220
xyObjectAnimators = java.lang.reflect.Array.newInstance(android.animation.Animator.class, 2);
213221

214-
originalValue = nativeView.getScaleX();
215222
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
216223
nativeArray[0] = propertyAnimation.value.x;
217224
xyObjectAnimators[0] = android.animation.ObjectAnimator.ofFloat(nativeView, "scaleX", nativeArray);
218225
xyObjectAnimators[0].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations));
219-
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.scaleX = propertyAnimation.value.x; }));
220-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setScaleX(originalValue); }));
221226

222-
originalValue = nativeView.getScaleY();
223227
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
224228
nativeArray[0] = propertyAnimation.value.y;
225229
xyObjectAnimators[1] = android.animation.ObjectAnimator.ofFloat(nativeView, "scaleY", nativeArray);
226230
xyObjectAnimators[1].setRepeatCount(Animation._getAndroidRepeatCount(propertyAnimation.iterations));
227-
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.scaleY = propertyAnimation.value.y; }));
228-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setScaleY(originalValue); }));
231+
232+
originalValue1 = nativeView.getScaleX();
233+
originalValue2 = nativeView.getScaleY();
234+
235+
propertyUpdateCallbacks.push(checkAnimation(() => {
236+
propertyAnimation.target.scaleX = propertyAnimation.value.x;
237+
propertyAnimation.target.scaleY = propertyAnimation.value.y;
238+
}));
239+
240+
propertyResetCallbacks.push(checkAnimation(() => {
241+
nativeView.setScaleY(originalValue1);
242+
nativeView.setScaleY(originalValue2);
243+
}));
229244

230245
animatorSet = new android.animation.AnimatorSet();
231246
animatorSet.playTogether(xyObjectAnimators);
@@ -234,11 +249,11 @@ export class Animation extends common.Animation implements definition.Animation
234249
break;
235250

236251
case common.Properties.rotate:
237-
originalValue = nativeView.getRotation();
252+
originalValue1 = nativeView.getRotation();
238253
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
239254
nativeArray[0] = propertyAnimation.value;
240255
propertyUpdateCallbacks.push(checkAnimation(() => { propertyAnimation.target.rotate = propertyAnimation.value; }));
241-
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setRotation(originalValue); }));
256+
propertyResetCallbacks.push(checkAnimation(() => { nativeView.setRotation(originalValue1); }));
242257
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "rotation", nativeArray));
243258
break;
244259

0 commit comments

Comments
 (0)