Skip to content

Commit 2bff535

Browse files
manucorporatadamdbradley
authored andcommitted
fix(tabs): swipeBackEnabled works with tabs as expected
1 parent aea866a commit 2bff535

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

src/components/input/native-input.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class NativeInput {
3131
}
3232

3333
@HostListener('input', ['$event'])
34-
private _change(ev) {
34+
private _change(ev: any) {
3535
this.valueChange.emit(ev.target.value);
3636
}
3737

@@ -40,9 +40,9 @@ export class NativeInput {
4040
var self = this;
4141

4242
self.focusChange.emit(true);
43-
44-
function docTouchEnd(ev) {
45-
var tapped: HTMLElement = ev.target;
43+
44+
function docTouchEnd(ev: TouchEvent) {
45+
var tapped = <HTMLElement>ev.target;
4646
if (tapped && self.element()) {
4747
if (tapped.tagName !== 'INPUT' && tapped.tagName !== 'TEXTAREA' && !tapped.classList.contains('input-cover')) {
4848
self.element().blur();
@@ -178,7 +178,7 @@ export class NativeInput {
178178

179179
}
180180

181-
function cloneInput(focusedInputEle, addCssClass) {
181+
function cloneInput(focusedInputEle: any, addCssClass: string) {
182182
let clonedInputEle = focusedInputEle.cloneNode(true);
183183
clonedInputEle.classList.add('cloned-input');
184184
clonedInputEle.classList.add(addCssClass);
@@ -191,7 +191,7 @@ function cloneInput(focusedInputEle, addCssClass) {
191191
return clonedInputEle;
192192
}
193193

194-
function removeClone(focusedInputEle, queryCssClass) {
194+
function removeClone(focusedInputEle: any, queryCssClass: string) {
195195
let clonedInputEle = focusedInputEle.parentElement.querySelector('.' + queryCssClass);
196196
if (clonedInputEle) {
197197
clonedInputEle.parentNode.removeChild(clonedInputEle);

src/components/nav/nav-controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,13 @@ export class NavController extends Ion {
17831783
return this._views.length;
17841784
}
17851785

1786+
/**
1787+
* @private
1788+
*/
1789+
isSwipeBackEnabled(): boolean {
1790+
return this._sbEnabled;
1791+
}
1792+
17861793
/**
17871794
* Returns the root `NavController`.
17881795
* @returns {NavController}

src/components/nav/nav.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export class Nav extends NavController implements AfterViewInit {
191191
get swipeBackEnabled(): boolean {
192192
return this._sbEnabled;
193193
}
194-
195194
set swipeBackEnabled(val: boolean) {
196195
this._sbEnabled = isTrueProperty(val);
197196
}

src/components/tabs/tab.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ export class Tab extends NavController {
201201
this._isShown = isTrueProperty(val);
202202
}
203203

204+
/**
205+
* @input {boolean} Whether it's possible to swipe-to-go-back on this tab or not.
206+
*/
207+
@Input()
208+
get swipeBackEnabled(): boolean {
209+
return this._sbEnabled;
210+
}
211+
set swipeBackEnabled(val: boolean) {
212+
this._sbEnabled = isTrueProperty(val);
213+
}
214+
204215
/**
205216
* @output {Tab} Method to call when the current tab is selected
206217
*/
@@ -222,6 +233,10 @@ export class Tab extends NavController {
222233

223234
parentTabs.add(this);
224235

236+
if (parentTabs.rootNav) {
237+
this._sbEnabled = parentTabs.rootNav.isSwipeBackEnabled();
238+
}
239+
225240
this._panelId = 'tabpanel-' + this.id;
226241
this._btnId = 'tab-' + this.id;
227242
}

src/components/tabs/test/advanced/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class Tab3Page1 {
411411

412412

413413
@Component({
414-
template: '<ion-nav [root]="root"></ion-nav>'
414+
template: '<ion-nav [root]="root" swipeBackEnabled="false"></ion-nav>'
415415
})
416416
class E2EApp {
417417
root = SignIn;

src/components/tabs/test/advanced/tabs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
<ion-tabs preloadTabs="false" (ionChange)="onTabChange()">
3-
<ion-tab tabTitle="Recents" tabIcon="call" [root]="tab1Root" [rootParams]="params"></ion-tab>
3+
<ion-tab tabTitle="Recents" tabIcon="call" [root]="tab1Root" [rootParams]="params" swipeBackEnabled="true"></ion-tab>
44
<ion-tab tabTitle="Favorites" tabIcon="star" [root]="tab2Root"></ion-tab>
55
<ion-tab tabTitle="Settings" tabIcon="settings" [root]="tab3Root"></ion-tab>
66
<ion-tab tabTitle="Chat" tabIcon="chatbubbles" (ionSelect)="chat()"></ion-tab>

0 commit comments

Comments
 (0)