mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-03 11:44:40 +08:00
fix(animation): avoid uncaught reject on cancel (#10309)
This commit is contained in:
@ -248,7 +248,7 @@ export class Animation extends AnimationBase {
|
|||||||
private _onAndroidAnimationCancel() {
|
private _onAndroidAnimationCancel() {
|
||||||
// tslint:disable-line
|
// tslint:disable-line
|
||||||
this._propertyResetCallbacks.forEach((v) => v());
|
this._propertyResetCallbacks.forEach((v) => v());
|
||||||
this._rejectAnimationFinishedPromise();
|
this._resolveAnimationFinishedPromise();
|
||||||
|
|
||||||
if (this._target) {
|
if (this._target) {
|
||||||
this._target._removeAnimation(this);
|
this._target._removeAnimation(this);
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import { AnimationBase, Properties, CubicBezierAnimationCurve } from './animatio
|
|||||||
import { Trace } from '../../trace';
|
import { Trace } from '../../trace';
|
||||||
import { opacityProperty, backgroundColorProperty, rotateProperty, rotateXProperty, rotateYProperty, translateXProperty, translateYProperty, scaleXProperty, scaleYProperty, heightProperty, widthProperty, PercentLength } from '../styling/style-properties';
|
import { opacityProperty, backgroundColorProperty, rotateProperty, rotateXProperty, rotateYProperty, translateXProperty, translateYProperty, scaleXProperty, scaleYProperty, heightProperty, widthProperty, PercentLength } from '../styling/style-properties';
|
||||||
|
|
||||||
import { iOSNativeHelper } from '../../utils/native-helper';
|
import { ios as iosHelper } from '../../utils/native-helper';
|
||||||
|
|
||||||
import { Screen } from '../../platform';
|
import { Screen } from '../../platform';
|
||||||
|
|
||||||
@ -168,33 +168,28 @@ export class Animation extends AnimationBase {
|
|||||||
this._mergedPropertyAnimations = this._propertyAnimations;
|
this._mergedPropertyAnimations = this._propertyAnimations;
|
||||||
}
|
}
|
||||||
|
|
||||||
const that = this;
|
|
||||||
const animationFinishedCallback = (cancelled: boolean) => {
|
const animationFinishedCallback = (cancelled: boolean) => {
|
||||||
if (that._playSequentially) {
|
if (this._playSequentially) {
|
||||||
// This function will be called by the last animation when done or by another animation if the user cancels them halfway through.
|
// This function will be called by the last animation when done or by another animation if the user cancels them halfway through.
|
||||||
if (cancelled) {
|
this._resolveAnimationFinishedPromise();
|
||||||
that._rejectAnimationFinishedPromise();
|
|
||||||
} else {
|
|
||||||
that._resolveAnimationFinishedPromise();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// This callback will be called by each INDIVIDUAL animation when it finishes or is cancelled.
|
// This callback will be called by each INDIVIDUAL animation when it finishes or is cancelled.
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
that._cancelledAnimations++;
|
this._cancelledAnimations++;
|
||||||
} else {
|
} else {
|
||||||
that._finishedAnimations++;
|
this._finishedAnimations++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (that._cancelledAnimations > 0 && that._cancelledAnimations + that._finishedAnimations === that._mergedPropertyAnimations.length) {
|
if (this._cancelledAnimations > 0 && this._cancelledAnimations + this._finishedAnimations === this._mergedPropertyAnimations.length) {
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(that._cancelledAnimations + ' animations cancelled.', Trace.categories.Animation);
|
Trace.write(this._cancelledAnimations + ' animations cancelled.', Trace.categories.Animation);
|
||||||
}
|
}
|
||||||
that._rejectAnimationFinishedPromise();
|
this._resolveAnimationFinishedPromise();
|
||||||
} else if (that._finishedAnimations === that._mergedPropertyAnimations.length) {
|
} else if (this._finishedAnimations === this._mergedPropertyAnimations.length) {
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(that._finishedAnimations + ' animations finished.', Trace.categories.Animation);
|
Trace.write(this._finishedAnimations + ' animations finished.', Trace.categories.Animation);
|
||||||
}
|
}
|
||||||
that._resolveAnimationFinishedPromise();
|
this._resolveAnimationFinishedPromise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -719,7 +714,7 @@ function calculateTransform(view: View): CATransform3D {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expectedTransform = CATransform3DTranslate(expectedTransform, view.translateX, view.translateY, 0);
|
expectedTransform = CATransform3DTranslate(expectedTransform, view.translateX, view.translateY, 0);
|
||||||
expectedTransform = iOSNativeHelper.applyRotateTransform(expectedTransform, view.rotateX, view.rotateY, view.rotate);
|
expectedTransform = iosHelper.applyRotateTransform(expectedTransform, view.rotateX, view.rotateY, view.rotate);
|
||||||
expectedTransform = CATransform3DScale(expectedTransform, scaleX, scaleY, 1);
|
expectedTransform = CATransform3DScale(expectedTransform, scaleX, scaleY, 1);
|
||||||
|
|
||||||
return expectedTransform;
|
return expectedTransform;
|
||||||
|
|||||||
Reference in New Issue
Block a user