Skip to content

Commit

Permalink
fix(tabs): swipeBackEnabled works with tabs as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored and adamdbradley committed Jun 21, 2016
1 parent aea866a commit 2bff535
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/components/input/native-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class NativeInput {
}

@HostListener('input', ['$event'])
private _change(ev) {
private _change(ev: any) {
this.valueChange.emit(ev.target.value);
}

Expand All @@ -40,9 +40,9 @@ export class NativeInput {
var self = this;

self.focusChange.emit(true);

function docTouchEnd(ev) {
var tapped: HTMLElement = ev.target;
function docTouchEnd(ev: TouchEvent) {
var tapped = <HTMLElement>ev.target;
if (tapped && self.element()) {
if (tapped.tagName !== 'INPUT' && tapped.tagName !== 'TEXTAREA' && !tapped.classList.contains('input-cover')) {
self.element().blur();
Expand Down Expand Up @@ -178,7 +178,7 @@ export class NativeInput {

}

function cloneInput(focusedInputEle, addCssClass) {
function cloneInput(focusedInputEle: any, addCssClass: string) {
let clonedInputEle = focusedInputEle.cloneNode(true);
clonedInputEle.classList.add('cloned-input');
clonedInputEle.classList.add(addCssClass);
Expand All @@ -191,7 +191,7 @@ function cloneInput(focusedInputEle, addCssClass) {
return clonedInputEle;
}

function removeClone(focusedInputEle, queryCssClass) {
function removeClone(focusedInputEle: any, queryCssClass: string) {
let clonedInputEle = focusedInputEle.parentElement.querySelector('.' + queryCssClass);
if (clonedInputEle) {
clonedInputEle.parentNode.removeChild(clonedInputEle);
Expand Down
7 changes: 7 additions & 0 deletions src/components/nav/nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,13 @@ export class NavController extends Ion {
return this._views.length;
}

/**
* @private
*/
isSwipeBackEnabled(): boolean {
return this._sbEnabled;
}

/**
* Returns the root `NavController`.
* @returns {NavController}
Expand Down
1 change: 0 additions & 1 deletion src/components/nav/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export class Nav extends NavController implements AfterViewInit {
get swipeBackEnabled(): boolean {
return this._sbEnabled;
}

set swipeBackEnabled(val: boolean) {
this._sbEnabled = isTrueProperty(val);
}
Expand Down
15 changes: 15 additions & 0 deletions src/components/tabs/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ export class Tab extends NavController {
this._isShown = isTrueProperty(val);
}

/**
* @input {boolean} Whether it's possible to swipe-to-go-back on this tab or not.
*/
@Input()
get swipeBackEnabled(): boolean {
return this._sbEnabled;
}
set swipeBackEnabled(val: boolean) {
this._sbEnabled = isTrueProperty(val);
}

/**
* @output {Tab} Method to call when the current tab is selected
*/
Expand All @@ -222,6 +233,10 @@ export class Tab extends NavController {

parentTabs.add(this);

if (parentTabs.rootNav) {
this._sbEnabled = parentTabs.rootNav.isSwipeBackEnabled();
}

this._panelId = 'tabpanel-' + this.id;
this._btnId = 'tab-' + this.id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/test/advanced/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class Tab3Page1 {


@Component({
template: '<ion-nav [root]="root"></ion-nav>'
template: '<ion-nav [root]="root" swipeBackEnabled="false"></ion-nav>'
})
class E2EApp {
root = SignIn;
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/test/advanced/tabs.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

0 comments on commit 2bff535

Please sign in to comment.