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

fix(animations): change throw -> trace to avoid unnecessary app crash · NativeScript/NativeScript@1d7fac2 · GitHub

Commit 1d7fac2

Browse files
committed
fix(animations): change throw -> trace to avoid unnecessary app crash
Fixes major cause of crashes/bugs in production apps using animation.
1 parent fb5c97c commit 1d7fac2

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ export abstract class AnimationBase implements AnimationBaseDefinition {
8686

8787
public play(): AnimationPromiseDefinition {
8888
if (this.isPlaying) {
89-
throw new Error("Animation is already playing.");
89+
if (traceEnabled()) {
90+
traceWrite("Animation is already playing.", traceCategories.Animation, 2);
91+
}
92+
return <AnimationPromiseDefinition>new Promise<void>((resolve, reject) => {
93+
reject();
94+
});
9095
}
9196

9297
// We have to actually create a "Promise" due to a bug in the v8 engine and decedent promises
@@ -124,7 +129,9 @@ export abstract class AnimationBase implements AnimationBaseDefinition {
124129

125130
public cancel(): void {
126131
if (!this.isPlaying) {
127-
throw new Error("Animation is not currently playing.");
132+
if (traceEnabled()) {
133+
traceWrite("Animation is not currently playing.", traceCategories.Animation, 2);
134+
}
128135
}
129136
}
130137

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { View, Color } from "../core/view";
1212

1313
import { AnimationCurve } from "../enums";
1414

15+
import { isEnabled as traceEnabled, write as traceWrite, categories as traceCategories } from "../../trace";
16+
1517
// Types.
1618
import { unsetValue } from "../core/properties";
1719
import { Animation } from "./animation";
@@ -161,7 +163,12 @@ export class KeyframeAnimation implements KeyframeAnimationDefinition {
161163

162164
public play(view: View): Promise<void> {
163165
if (this._isPlaying) {
164-
throw new Error("Animation is already playing.");
166+
if (traceEnabled()) {
167+
traceWrite("Keyframe animation is already playing.", traceCategories.Animation, 2);
168+
}
169+
return new Promise<void>((resolve, reject) => {
170+
reject();
171+
});
165172
}
166173

167174
let animationFinishedPromise = new Promise<void>((resolve, reject) => {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL