mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(animation): handle promise rejection and avoid throw (#5861)
This commit is contained in:
committed by
Alexander Vakrilov
parent
b77675b312
commit
9308bab172
@@ -74,7 +74,6 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
|
||||
public iterations: number = 1;
|
||||
|
||||
private _resolve;
|
||||
private _reject;
|
||||
private _isPlaying: boolean;
|
||||
private _isForwards: boolean;
|
||||
private _nativeAnimations: Array<Animation>;
|
||||
@@ -161,21 +160,19 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
|
||||
let animation = this._nativeAnimations[0];
|
||||
this._resetAnimationValues(this._target, animation);
|
||||
}
|
||||
this._rejectAnimationFinishedPromise();
|
||||
this._resetAnimations();
|
||||
}
|
||||
|
||||
public play(view: View): Promise<void> {
|
||||
if (this._isPlaying) {
|
||||
const reason = "Keyframe animation is already playing.";
|
||||
traceWrite(reason, traceCategories.Animation, traceType.warn);
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
reject(reason);
|
||||
traceWrite("Keyframe animation is already playing.", traceCategories.Animation, traceType.warn);
|
||||
return new Promise<void>(resolve => {
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
let animationFinishedPromise = new Promise<void>((resolve, reject) => {
|
||||
let animationFinishedPromise = new Promise<void>(resolve => {
|
||||
this._resolve = resolve;
|
||||
this._reject = reject;
|
||||
});
|
||||
|
||||
this._isPlaying = true;
|
||||
@@ -239,10 +236,10 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
|
||||
// Catch the animation cancel to prevent unhandled promise rejection warnings
|
||||
animation.play().then(() => {
|
||||
this.animate(view, index + 1, iterations);
|
||||
}, (error: any) => {
|
||||
traceWrite(typeof error === "string" ? error : error.message, traceCategories.Animation, traceType.warn);
|
||||
}).catch((error: any) => {
|
||||
if (error.message.indexOf("Animation cancelled") < 0) {
|
||||
throw error;
|
||||
}
|
||||
traceWrite(typeof error === "string" ? error : error.message, traceCategories.Animation, traceType.warn);
|
||||
}); // tslint:disable-line
|
||||
this._nativeAnimations.push(animation);
|
||||
}
|
||||
@@ -255,11 +252,10 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
|
||||
this._resolve();
|
||||
}
|
||||
|
||||
public _rejectAnimationFinishedPromise() {
|
||||
public _resetAnimations() {
|
||||
this._nativeAnimations = new Array<Animation>();
|
||||
this._isPlaying = false;
|
||||
this._target = null;
|
||||
this._reject(new Error("Animation cancelled."));
|
||||
}
|
||||
|
||||
private _resetAnimationValues(view: View, animation: Object) {
|
||||
|
||||
Reference in New Issue
Block a user