From 04e78d8c228c15bd9efd5ac5deede23f34e83787 Mon Sep 17 00:00:00 2001 From: Dan Bucholtz Date: Fri, 30 Jun 2017 11:34:08 -0500 Subject: [PATCH] fix(navigation): fix swipe-to-go-back fix swipe-to-go-back --- src/navigation/nav-controller-base.ts | 2 +- src/navigation/test/nav-controller.spec.ts | 46 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/navigation/nav-controller-base.ts b/src/navigation/nav-controller-base.ts index 0d387924e26..5d337e4fbca 100644 --- a/src/navigation/nav-controller-base.ts +++ b/src/navigation/nav-controller-base.ts @@ -1048,7 +1048,7 @@ export class NavControllerBase extends Ion implements NavController { canSwipeBack(): boolean { return (this._sbEnabled && !this._isPortal && - this._child && + !this._child && !this.isTransitioning() && this._app.isEnabled() && this.canGoBack()); diff --git a/src/navigation/test/nav-controller.spec.ts b/src/navigation/test/nav-controller.spec.ts index 59f897c5f1c..3387a71c69e 100644 --- a/src/navigation/test/nav-controller.spec.ts +++ b/src/navigation/test/nav-controller.spec.ts @@ -1100,7 +1100,53 @@ describe('NavController', () => { }); nav.destroy(); }, 10000); + }); + + describe('canSwipeBack', () => { + it('should not swipe back when its not enabled', () => { + nav._sbEnabled = false; + + const view1 = mockView(); + const view2 = mockView(); + mockViews(nav, [view1, view2]); + + const result = nav.canSwipeBack(); + expect(result).toEqual(false); + }); + + it('should not swipe back if its the portal', () => { + nav._sbEnabled = true; + nav._isPortal = true; + const view1 = mockView(); + const view2 = mockView(); + mockViews(nav, [view1, view2]); + + const result = nav.canSwipeBack(); + expect(result).toEqual(false); + }); + + it('should not swipe back if it has a child nav', () => { + nav._sbEnabled = true; + nav._child = mockNavController(); + + const view1 = mockView(); + const view2 = mockView(); + mockViews(nav, [view1, view2]); + + const result = nav.canSwipeBack(); + expect(result).toEqual(false); + }); + + it('should swipe back when has a view to go back to', () => { + nav._sbEnabled = true; + const view1 = mockView(); + const view2 = mockView(); + mockViews(nav, [view1, view2]); + + const result = nav.canSwipeBack(); + expect(result).toEqual(true); + }); });