FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(animation): handle promise rejection and avoid throw (#5861) · NativeScript/NativeScript@9308bab · GitHub

Commit 9308bab

Browse files
authored andcommitted
fix(animation): handle promise rejection and avoid throw (#5861)
1 parent b77675b commit 9308bab

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

‎tns-core-modules/ui/animation/keyframe-animation.ts‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
7474
public iterations: number = 1;
7575

7676
private _resolve;
77-
private _reject;
7877
private _isPlaying: boolean;
7978
private _isForwards: boolean;
8079
private _nativeAnimations: Array<Animation>;
@@ -161,21 +160,19 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
161160
let animation = this._nativeAnimations[0];
162161
this._resetAnimationValues(this._target, animation);
163162
}
164-
this._rejectAnimationFinishedPromise();
163+
this._resetAnimations();
165164
}
166165

167166
public play(view: View): Promise<void> {
168167
if (this._isPlaying) {
169-
const reason = "Keyframe animation is already playing.";
170-
traceWrite(reason, traceCategories.Animation, traceType.warn);
171-
return new Promise<void>((resolve, reject) => {
172-
reject(reason);
168+
traceWrite("Keyframe animation is already playing.", traceCategories.Animation, traceType.warn);
169+
return new Promise<void>(resolve => {
170+
resolve();
173171
});
174172
}
175173

176-
let animationFinishedPromise = new Promise<void>((resolve, reject) => {
174+
let animationFinishedPromise = new Promise<void>(resolve => {
177175
this._resolve = resolve;
178-
this._reject = reject;
179176
});
180177

181178
this._isPlaying = true;
@@ -239,10 +236,10 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
239236
// Catch the animation cancel to prevent unhandled promise rejection warnings
240237
animation.play().then(() => {
241238
this.animate(view, index + 1, iterations);
239+
}, (error: any) => {
240+
traceWrite(typeof error === "string" ? error : error.message, traceCategories.Animation, traceType.warn);
242241
}).catch((error: any) => {
243-
if (error.message.indexOf("Animation cancelled") < 0) {
244-
throw error;
245-
}
242+
traceWrite(typeof error === "string" ? error : error.message, traceCategories.Animation, traceType.warn);
246243
}); // tslint:disable-line
247244
this._nativeAnimations.push(animation);
248245
}
@@ -255,11 +252,10 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
255252
this._resolve();
256253
}
257254

258-
public _rejectAnimationFinishedPromise() {
255+
public _resetAnimations() {
259256
this._nativeAnimations = new Array<Animation>();
260257
this._isPlaying = false;
261258
this._target = null;
262-
this._reject(new Error("Animation cancelled."));
263259
}
264260

265261
private _resetAnimationValues(view: View, animation: Object) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL