mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Implemented #1102: Ability to specify an animation easing, i.e. curve in a platform-independent manner.
This commit is contained in:
@@ -61,6 +61,7 @@ export class Animation implements definition.Animation {
|
||||
var i = 0;
|
||||
var length = animationDefinitions.length;
|
||||
for (; i < length; i++) {
|
||||
animationDefinitions[i].curve = this._resolveAnimationCurve(animationDefinitions[i].curve);
|
||||
this._propertyAnimations = this._propertyAnimations.concat(Animation._createPropertyAnimations(animationDefinitions[i]));
|
||||
}
|
||||
|
||||
@@ -82,6 +83,10 @@ export class Animation implements definition.Animation {
|
||||
this._reject(new Error("Animation cancelled."));
|
||||
}
|
||||
|
||||
_resolveAnimationCurve(curve: any): any {
|
||||
//
|
||||
}
|
||||
|
||||
private static _createPropertyAnimations(animationDefinition: definition.AnimationDefinition): Array<PropertyAnimation> {
|
||||
if (!animationDefinition.target) {
|
||||
throw new Error("No animation target specified.");
|
||||
|
||||
@@ -4,6 +4,7 @@ import utils = require("utils/utils");
|
||||
import color = require("color");
|
||||
import trace = require("trace");
|
||||
import types = require("utils/types");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
@@ -277,6 +278,26 @@ export class Animation extends common.Animation implements definition.Animation
|
||||
this._propertyResetCallbacks = this._propertyResetCallbacks.concat(propertyResetCallbacks);
|
||||
}
|
||||
|
||||
_resolveAnimationCurve(curve: any): any {
|
||||
switch (curve) {
|
||||
case enums.AnimationCurve.easeIn:
|
||||
trace.write("Animation curve resolved to android.view.animation.AccelerateInterpolator(1).", trace.categories.Animation);
|
||||
return new android.view.animation.AccelerateInterpolator(1);
|
||||
case enums.AnimationCurve.easeOut:
|
||||
trace.write("Animation curve resolved to android.view.animation.DecelerateInterpolator(1).", trace.categories.Animation);
|
||||
return new android.view.animation.DecelerateInterpolator(1);
|
||||
case enums.AnimationCurve.easeInOut:
|
||||
trace.write("Animation curve resolved to android.view.animation.AccelerateDecelerateInterpolator().", trace.categories.Animation);
|
||||
return new android.view.animation.AccelerateDecelerateInterpolator();
|
||||
case enums.AnimationCurve.linear:
|
||||
trace.write("Animation curve resolved to android.view.animation.LinearInterpolator().", trace.categories.Animation);
|
||||
return new android.view.animation.LinearInterpolator();
|
||||
default:
|
||||
trace.write("Animation curve resolved to original: " + curve, trace.categories.Animation);
|
||||
return curve;
|
||||
}
|
||||
}
|
||||
|
||||
private static _getAndroidRepeatCount(iterations: number): number {
|
||||
return (iterations === Number.POSITIVE_INFINITY) ? android.view.animation.Animation.INFINITE : iterations - 1;
|
||||
}
|
||||
|
||||
6
ui/animation/animation.d.ts
vendored
6
ui/animation/animation.d.ts
vendored
@@ -54,7 +54,8 @@
|
||||
iterations?: number;
|
||||
|
||||
/**
|
||||
* An optional animation curve of type UIViewAnimationCurve for iOS or android.animation.TimeInterpolator for Android.
|
||||
* An optional animation curve. Possible values are contained in the [AnimationCurve enumeration](../enums/AnimationCurve/README.md).
|
||||
* Alternatively, you can pass an instance of type UIViewAnimationCurve for iOS or android.animation.TimeInterpolator for Android.
|
||||
*/
|
||||
curve?: any;
|
||||
}
|
||||
@@ -75,5 +76,8 @@
|
||||
public play: () => Promise<void>;
|
||||
public cancel: () => void;
|
||||
public isPlaying: boolean;
|
||||
//@private
|
||||
_resolveAnimationCurve(curve: any): any
|
||||
//@endprivate
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
import common = require("./animation-common");
|
||||
import viewModule = require("ui/core/view");
|
||||
import trace = require("trace");
|
||||
import enums = require("ui/enums");
|
||||
|
||||
global.moduleMerge(common, exports);
|
||||
|
||||
@@ -143,6 +144,26 @@ export class Animation extends common.Animation implements definition.Animation
|
||||
this._iOSAnimationFunction = Animation._createiOSAnimationFunction(this._mergedPropertyAnimations, 0, this._playSequentially, animationFinishedCallback);
|
||||
}
|
||||
|
||||
_resolveAnimationCurve(curve: any): any {
|
||||
switch (curve) {
|
||||
case enums.AnimationCurve.easeIn:
|
||||
trace.write("Animation curve resolved to UIViewAnimationCurve.UIViewAnimationCurveEaseIn.", trace.categories.Animation);
|
||||
return UIViewAnimationCurve.UIViewAnimationCurveEaseIn;
|
||||
case enums.AnimationCurve.easeOut:
|
||||
trace.write("Animation curve resolved to UIViewAnimationCurve.UIViewAnimationCurveEaseOut.", trace.categories.Animation);
|
||||
return UIViewAnimationCurve.UIViewAnimationCurveEaseOut;
|
||||
case enums.AnimationCurve.easeInOut:
|
||||
trace.write("Animation curve resolved to UIViewAnimationCurve.UIViewAnimationCurveEaseInOut.", trace.categories.Animation);
|
||||
return UIViewAnimationCurve.UIViewAnimationCurveEaseInOut;
|
||||
case enums.AnimationCurve.linear:
|
||||
trace.write("Animation curve resolved to UIViewAnimationCurve.UIViewAnimationCurveLinear.", trace.categories.Animation);
|
||||
return UIViewAnimationCurve.UIViewAnimationCurveLinear;
|
||||
default:
|
||||
trace.write("Animation curve resolved to original: " + curve, trace.categories.Animation);
|
||||
return curve;
|
||||
}
|
||||
}
|
||||
|
||||
private static _createiOSAnimationFunction(propertyAnimations: Array<common.PropertyAnimation>, index: number, playSequentially: boolean, finishedCallback: (cancelled?: boolean) => void): Function {
|
||||
return (cancelled?: boolean) => {
|
||||
if (cancelled && finishedCallback) {
|
||||
|
||||
25
ui/enums/enums.d.ts
vendored
25
ui/enums/enums.d.ts
vendored
@@ -492,4 +492,29 @@
|
||||
*/
|
||||
export var right: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an animation curve type.
|
||||
*/
|
||||
module AnimationCurve {
|
||||
/**
|
||||
* An ease-in curve causes the animation to begin slowly, and then speed up as it progresses.
|
||||
*/
|
||||
export var easeIn: string;
|
||||
|
||||
/**
|
||||
* An ease-out curve causes the animation to begin quickly, and then slow down as it completes.
|
||||
*/
|
||||
export var easeOut: string;
|
||||
|
||||
/**
|
||||
* An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing.
|
||||
*/
|
||||
export var easeInOut: string;
|
||||
|
||||
/**
|
||||
* A linear animation curve causes an animation to occur evenly over its duration.
|
||||
*/
|
||||
export var linear: string;
|
||||
}
|
||||
}
|
||||
@@ -149,3 +149,10 @@ export module BackgroundRepeat {
|
||||
export var repeatY: string = "repeat-y";
|
||||
export var noRepeat: string = "no-repeat";
|
||||
}
|
||||
|
||||
export module AnimationCurve {
|
||||
export var easeIn = "easeIn";
|
||||
export var easeOut = "easeOut";
|
||||
export var easeInOut = "easeInOut";
|
||||
export var linear = "linear";
|
||||
}
|
||||
Reference in New Issue
Block a user