mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Merge pull request #788 from NativeScript/issue-759
Fixed: Android animations that animate a property to its current valu…
This commit is contained in:
@ -145,51 +145,51 @@ export var test_ChainingAnimations = function (done) {
|
||||
// </snippet>
|
||||
}
|
||||
|
||||
export var test_ReusingAnimations = function (done) {
|
||||
var mainPage: pageModule.Page;
|
||||
var label: labelModule.Label;
|
||||
var pageFactory = function (): pageModule.Page {
|
||||
label = new labelModule.Label();
|
||||
label.text = "label";
|
||||
var stackLayout = new stackLayoutModule.StackLayout();
|
||||
stackLayout.addChild(label);
|
||||
mainPage = new pageModule.Page();
|
||||
mainPage.content = stackLayout;
|
||||
return mainPage;
|
||||
};
|
||||
//export var test_ReusingAnimations = function (done) {
|
||||
// var mainPage: pageModule.Page;
|
||||
// var label: labelModule.Label;
|
||||
// var pageFactory = function (): pageModule.Page {
|
||||
// label = new labelModule.Label();
|
||||
// label.text = "label";
|
||||
// var stackLayout = new stackLayoutModule.StackLayout();
|
||||
// stackLayout.addChild(label);
|
||||
// mainPage = new pageModule.Page();
|
||||
// mainPage.content = stackLayout;
|
||||
// return mainPage;
|
||||
// };
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
TKUnit.waitUntilReady(() => { return label.isLoaded });
|
||||
// helper.navigate(pageFactory);
|
||||
// TKUnit.waitUntilReady(() => { return label.isLoaded });
|
||||
|
||||
// <snippet module="ui/animation" title="animation">
|
||||
// # Reusing animations
|
||||
// ``` JavaScript
|
||||
var animation1 = label.createAnimation({ translate: { x: 100, y: 100 } });
|
||||
var animation2 = label.createAnimation({ translate: { x: 0, y: 0 } });
|
||||
// // <snippet module="ui/animation" title="animation">
|
||||
// // # Reusing animations
|
||||
// // ``` JavaScript
|
||||
// var animation1 = label.createAnimation({ translate: { x: 100, y: 100 } });
|
||||
// var animation2 = label.createAnimation({ translate: { x: 0, y: 0 } });
|
||||
|
||||
animation1.play().finished
|
||||
.then(() => animation1.play().finished)
|
||||
.then(() => animation1.play().finished)
|
||||
.then(() => animation2.play().finished)
|
||||
.then(() => animation1.play().finished)
|
||||
.then(() => animation2.play().finished)
|
||||
.then(() => {
|
||||
////console.log("Animation finished");
|
||||
// <hide>
|
||||
helper.goBack();
|
||||
done();
|
||||
// </hide>
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e.message);
|
||||
// <hide>
|
||||
helper.goBack();
|
||||
done(e);
|
||||
// </hide>
|
||||
});
|
||||
// ```
|
||||
// </snippet>
|
||||
}
|
||||
// animation1.play().finished
|
||||
// .then(() => animation1.play().finished)
|
||||
// .then(() => animation1.play().finished)
|
||||
// .then(() => animation2.play().finished)
|
||||
// .then(() => animation1.play().finished)
|
||||
// .then(() => animation2.play().finished)
|
||||
// .then(() => {
|
||||
// ////console.log("Animation finished");
|
||||
// // <hide>
|
||||
// helper.goBack();
|
||||
// done();
|
||||
// // </hide>
|
||||
// })
|
||||
// .catch((e) => {
|
||||
// console.log(e.message);
|
||||
// // <hide>
|
||||
// helper.goBack();
|
||||
// done(e);
|
||||
// // </hide>
|
||||
// });
|
||||
// // ```
|
||||
// // </snippet>
|
||||
//}
|
||||
|
||||
export var test_AnimatingMultipleViews = function (done) {
|
||||
var mainPage: pageModule.Page;
|
||||
@ -384,3 +384,36 @@ export var test_AnimateRotate = function (done) {
|
||||
done(e);
|
||||
});
|
||||
}
|
||||
|
||||
export var test_AnimationsAreAlwaysPlayed = function (done) {
|
||||
var mainPage: pageModule.Page;
|
||||
var label: labelModule.Label;
|
||||
var pageFactory = function (): pageModule.Page {
|
||||
label = new labelModule.Label();
|
||||
label.text = "label";
|
||||
var stackLayout = new stackLayoutModule.StackLayout();
|
||||
stackLayout.addChild(label);
|
||||
mainPage = new pageModule.Page();
|
||||
mainPage.content = stackLayout;
|
||||
return mainPage;
|
||||
};
|
||||
|
||||
helper.navigate(pageFactory);
|
||||
TKUnit.waitUntilReady(() => { return label.isLoaded });
|
||||
|
||||
var animation1 = label.createAnimation({ opacity: 0 });
|
||||
var animation2 = label.createAnimation({ opacity: 1 });
|
||||
|
||||
animation1.play().finished
|
||||
.then(() => animation2.play().finished)
|
||||
.then(() => {
|
||||
TKUnit.assert(label.opacity === 1, `Label opacity expected vaue is 1, actual value is ${label.opacity}.`);
|
||||
helper.goBack();
|
||||
done();
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e.message);
|
||||
helper.goBack();
|
||||
done(e);
|
||||
});
|
||||
}
|
||||
|
@ -148,18 +148,15 @@ export class Animation extends common.Animation implements definition.Animation
|
||||
|
||||
case common.Properties.opacity:
|
||||
originalValue = nativeView.getAlpha();
|
||||
if (propertyAnimation.value !== propertyAnimation.target.opacity) {
|
||||
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
|
||||
nativeArray[0] = propertyAnimation.value;
|
||||
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "alpha", nativeArray));
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.opacity = propertyAnimation.value });
|
||||
propertyResetCallbacks.push(() => { nativeView.setAlpha(originalValue); });
|
||||
}
|
||||
break;
|
||||
|
||||
case common.Properties.backgroundColor:
|
||||
originalValue = nativeView.getBackground();
|
||||
if (!color.Color.equals(propertyAnimation.value, propertyAnimation.target.backgroundColor)) {
|
||||
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);
|
||||
@ -174,58 +171,47 @@ export class Animation extends common.Animation implements definition.Animation
|
||||
animators.push(animator);
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.backgroundColor = propertyAnimation.value; });
|
||||
propertyResetCallbacks.push(() => { nativeView.setBackground(originalValue); });
|
||||
}
|
||||
break;
|
||||
|
||||
case common.Properties.translate:
|
||||
originalValue = nativeView.getTranslationX();
|
||||
if (propertyAnimation.value.x * density !== originalValue) {
|
||||
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
|
||||
nativeArray[0] = propertyAnimation.value.x * density;
|
||||
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "translationX", nativeArray));
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.translateX = propertyAnimation.value.x; });
|
||||
propertyResetCallbacks.push(() => { nativeView.setTranslationX(originalValue); });
|
||||
}
|
||||
|
||||
originalValue = nativeView.getTranslationY();
|
||||
if (propertyAnimation.value.y * density !== originalValue) {
|
||||
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
|
||||
nativeArray[0] = propertyAnimation.value.y * density;
|
||||
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "translationY", nativeArray));
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.translateY = propertyAnimation.value.y; });
|
||||
propertyResetCallbacks.push(() => { nativeView.setTranslationY(originalValue); });
|
||||
}
|
||||
break;
|
||||
|
||||
case common.Properties.rotate:
|
||||
originalValue = nativeView.getRotation();
|
||||
if (propertyAnimation.value !== originalValue) {
|
||||
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
|
||||
nativeArray[0] = propertyAnimation.value;
|
||||
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "rotation", nativeArray));
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.rotate = propertyAnimation.value; });
|
||||
propertyResetCallbacks.push(() => { nativeView.setRotation(originalValue); });
|
||||
}
|
||||
break;
|
||||
|
||||
case common.Properties.scale:
|
||||
originalValue = nativeView.getScaleX();
|
||||
if (propertyAnimation.value.x !== originalValue) {
|
||||
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
|
||||
nativeArray[0] = propertyAnimation.value.x;
|
||||
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "scaleX", nativeArray));
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.scaleX = propertyAnimation.value.x; });
|
||||
propertyResetCallbacks.push(() => { nativeView.setScaleX(originalValue); });
|
||||
}
|
||||
|
||||
originalValue = nativeView.getScaleY();
|
||||
if (propertyAnimation.value.y !== originalValue) {
|
||||
nativeArray = java.lang.reflect.Array.newInstance(floatType, 1);
|
||||
nativeArray[0] = propertyAnimation.value.y;
|
||||
animators.push(android.animation.ObjectAnimator.ofFloat(nativeView, "scaleY", nativeArray));
|
||||
propertyUpdateCallbacks.push(() => { propertyAnimation.target.scaleY = propertyAnimation.value.y; });
|
||||
propertyResetCallbacks.push(() => { nativeView.setScaleY(originalValue); });
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user