Skip to content

Commit 04e78d8

Browse files
committed
fix(navigation): fix swipe-to-go-back
fix swipe-to-go-back
1 parent 48b3243 commit 04e78d8

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/navigation/nav-controller-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ export class NavControllerBase extends Ion implements NavController {
10481048
canSwipeBack(): boolean {
10491049
return (this._sbEnabled &&
10501050
!this._isPortal &&
1051-
this._child &&
1051+
!this._child &&
10521052
!this.isTransitioning() &&
10531053
this._app.isEnabled() &&
10541054
this.canGoBack());

src/navigation/test/nav-controller.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,53 @@ describe('NavController', () => {
11001100
});
11011101
nav.destroy();
11021102
}, 10000);
1103+
});
1104+
1105+
describe('canSwipeBack', () => {
1106+
it('should not swipe back when its not enabled', () => {
1107+
nav._sbEnabled = false;
1108+
1109+
const view1 = mockView();
1110+
const view2 = mockView();
1111+
mockViews(nav, [view1, view2]);
1112+
1113+
const result = nav.canSwipeBack();
1114+
expect(result).toEqual(false);
1115+
});
1116+
1117+
it('should not swipe back if its the portal', () => {
1118+
nav._sbEnabled = true;
1119+
nav._isPortal = true;
11031120

1121+
const view1 = mockView();
1122+
const view2 = mockView();
1123+
mockViews(nav, [view1, view2]);
1124+
1125+
const result = nav.canSwipeBack();
1126+
expect(result).toEqual(false);
1127+
});
1128+
1129+
it('should not swipe back if it has a child nav', () => {
1130+
nav._sbEnabled = true;
1131+
nav._child = mockNavController();
1132+
1133+
const view1 = mockView();
1134+
const view2 = mockView();
1135+
mockViews(nav, [view1, view2]);
1136+
1137+
const result = nav.canSwipeBack();
1138+
expect(result).toEqual(false);
1139+
});
1140+
1141+
it('should swipe back when has a view to go back to', () => {
1142+
nav._sbEnabled = true;
1143+
const view1 = mockView();
1144+
const view2 = mockView();
1145+
mockViews(nav, [view1, view2]);
1146+
1147+
const result = nav.canSwipeBack();
1148+
expect(result).toEqual(true);
1149+
});
11041150
});
11051151

11061152

0 commit comments

Comments
 (0)