diff --git a/core/src/utils/animation/animation.ts b/core/src/utils/animation/animation.ts index c547bafd3c..14c609b103 100644 --- a/core/src/utils/animation/animation.ts +++ b/core/src/utils/animation/animation.ts @@ -579,6 +579,17 @@ export const createAnimation = (animationId?: string): Animation => { } }); + /** + * Clean up any value coercion before + * the user callbacks fire otherwise + * they may get stale values. For example, + * if someone calls progressStart(0) the + * animation may still be reversed. + */ + forceDurationValue = undefined; + forceDirectionValue = undefined; + forceDelayValue = undefined; + onFinishCallbacks.forEach((onFinishCallback) => { return onFinishCallback.c(currentStep, ani); }); @@ -826,21 +837,8 @@ export const createAnimation = (animationId?: string): Animation => { } } - if (playTo !== undefined) { - onFinish( - () => { - forceDurationValue = undefined; - forceDirectionValue = undefined; - forceDelayValue = undefined; - }, - { - oneTimeCallback: true, - } - ); - - if (!parentAnimation) { - play(); - } + if (playTo !== undefined && !parentAnimation) { + play(); } return ani; diff --git a/core/src/utils/animation/test/animation.spec.ts b/core/src/utils/animation/test/animation.spec.ts index b9cfb18c3d..0e4337e01c 100644 --- a/core/src/utils/animation/test/animation.spec.ts +++ b/core/src/utils/animation/test/animation.spec.ts @@ -4,6 +4,23 @@ import { processKeyframes } from '../animation-utils'; import { getTimeGivenProgression } from '../cubic-bezier'; describe('Animation Class', () => { + describe('progressEnd callbacks', () => { + test('coerced state should be reset before onFinish runs', (done) => { + const el = document.createElement('div'); + const animation = createAnimation() + .addElement(el) + .fromTo('transform', 'translateX(0px)', 'translateX(100px)') + .duration(50); + + animation + .onFinish(() => { + expect(animation.getDirection()).toBe('normal'); + expect(animation.getDuration()).toBe(50); + done(); + }) + .progressEnd(0, 0.5, 10); + }); + }); describe('play()', () => { it('should resolve when the animation is cancelled', async () => { // Tell Jest to expect 1 assertion for async code