From fd65765bdf018f7af6ab2d4fe79f7b64ffaf687b Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Fri, 16 Aug 2019 13:33:39 -0400 Subject: [PATCH] fix(nav): prevent completing transition from being interrupted (#19113) * do not enable swipe to begin before previous one has ended * update defaults * use canStart instead * pause animations on finish * remove old pause code --- core/src/components/nav/nav.tsx | 6 ++++++ core/src/components/router-outlet/route-outlet.tsx | 9 ++++++++- core/src/utils/animation/animation.ts | 13 ++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/src/components/nav/nav.tsx b/core/src/components/nav/nav.tsx index eed8403d1c..07fc883a8b 100644 --- a/core/src/components/nav/nav.tsx +++ b/core/src/components/nav/nav.tsx @@ -18,6 +18,7 @@ export class Nav implements NavOutlet { private transInstr: TransitionInstruction[] = []; private sbAni?: Animation | IonicAnimation; + private animationEnabled = true; private useRouter = false; private isTransitioning = false; private destroyed = false; @@ -937,6 +938,7 @@ export class Nav implements NavOutlet { !!this.swipeGesture && !this.isTransitioning && this.transInstr.length === 0 && + this.animationEnabled && this.canGoBackSync() ); } @@ -960,6 +962,10 @@ export class Nav implements NavOutlet { private onEnd(shouldComplete: boolean, stepValue: number, dur: number) { if (this.sbAni) { + this.animationEnabled = false; + this.sbAni.onFinish(() => { + this.animationEnabled = true; + }, { oneTimeCallback: true }); this.sbAni.progressEnd(shouldComplete, stepValue, dur); } } diff --git a/core/src/components/router-outlet/route-outlet.tsx b/core/src/components/router-outlet/route-outlet.tsx index 92ffad535a..6c2f244bee 100644 --- a/core/src/components/router-outlet/route-outlet.tsx +++ b/core/src/components/router-outlet/route-outlet.tsx @@ -18,6 +18,7 @@ export class RouterOutlet implements ComponentInterface, NavOutlet { private waitPromise?: Promise; private gesture?: Gesture; private ani?: IonicAnimation | Animation; + private animationEnabled = true; @Element() el!: HTMLElement; @@ -65,12 +66,18 @@ export class RouterOutlet implements ComponentInterface, NavOutlet { async componentDidLoad() { this.gesture = (await import('../../utils/gesture/swipe-back')).createSwipeBackGesture( this.el, - () => !!this.swipeHandler && this.swipeHandler.canStart(), + () => !!this.swipeHandler && this.swipeHandler.canStart() && this.animationEnabled, () => this.swipeHandler && this.swipeHandler.onStart(), step => this.ani && this.ani.progressStep(step), (shouldComplete, step, dur) => { if (this.ani) { + this.animationEnabled = false; + this.ani.onFinish(() => { + this.animationEnabled = true; + }, { oneTimeCallback: true }); + this.ani.progressEnd(shouldComplete, step, dur); + } if (this.swipeHandler) { this.swipeHandler.onEnd(shouldComplete); diff --git a/core/src/utils/animation/animation.ts b/core/src/utils/animation/animation.ts index fbbc4afc71..3d0a3cd344 100644 --- a/core/src/utils/animation/animation.ts +++ b/core/src/utils/animation/animation.ts @@ -604,7 +604,7 @@ export const createAnimation = () => { } }; - const initializeCSSAnimation = () => { + const initializeCSSAnimation = (toggleAnimationName = true) => { cleanUpStyleSheets(); elements.forEach(element => { @@ -628,7 +628,10 @@ export const createAnimation = () => { setStyleProperty(element, 'animation-iteration-count', iterationsCount); setStyleProperty(element, 'animation-play-state', 'paused'); - setStyleProperty(element, 'animation-name', `${stylesheet.id}-alt`); + if (toggleAnimationName) { + setStyleProperty(element, 'animation-name', `${stylesheet.id}-alt`); + } + requestAnimationFrame(() => { setStyleProperty(element, 'animation-name', stylesheet.id || null); }); @@ -660,14 +663,14 @@ export const createAnimation = () => { }; - const initializeAnimation = () => { + const initializeAnimation = (toggleAnimationName = true) => { beforeAnimation(); if (_keyframes.length > 0) { if (supportsWebAnimations) { initializeWebAnimation(); } else { - initializeCSSAnimation(); + initializeCSSAnimation(toggleAnimationName); } } @@ -968,7 +971,7 @@ export const createAnimation = () => { */ const play = () => { if (!initialized) { - initializeAnimation(); + initializeAnimation(false); } if (finished) {