Skip to content

Commit

Permalink
fix(tabs): hide tabbar when keyboard opens
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed May 19, 2017
1 parent bedcd04 commit 09666bb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
27 changes: 25 additions & 2 deletions src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Config } from '../../config/config';
import { DeepLinker } from '../../navigation/deep-linker';
import { Ion } from '../ion';
import { isBlank, assert } from '../../util/util';
import { Keyboard } from '../../platform/keyboard';
import { Tabs as ITabs } from '../../navigation/nav-interfaces';
import { NavController } from '../../navigation/nav-controller';
import { NavControllerBase } from '../../navigation/nav-controller-base';
Expand Down Expand Up @@ -151,7 +152,7 @@ import { ViewController } from '../../navigation/view-controller';
@Component({
selector: 'ion-tabs',
template:
'<div class="tabbar" role="tablist" #tabbar>' +
'<div class="tabbar" role="tablist" #tabbar [hidden]="_tabbarHidden">' +
'<a *ngFor="let t of _tabs" [tab]="t" class="tab-button" role="tab" href="#" (ionSelect)="select(t)"></a>' +
'<div class="tab-highlight"></div>' +
'</div>' +
Expand All @@ -177,6 +178,10 @@ export class Tabs extends Ion implements AfterViewInit, RootNode, ITabs {
_selectHistory: string[] = [];
/** @internal */
_resizeObs: any;
/** @internal */
_keyboardObs: any;
/** @internal */
_tabbarHidden = false;

/**
* @input {number} The default selected tab index when first loaded. If a selected index isn't provided then it will use `0`, the first tab.
Expand Down Expand Up @@ -231,7 +236,8 @@ export class Tabs extends Ion implements AfterViewInit, RootNode, ITabs {
elementRef: ElementRef,
private _plt: Platform,
renderer: Renderer,
private _linker: DeepLinker
private _linker: DeepLinker,
keyboard?: Keyboard
) {
super(config, elementRef, renderer, 'tabs');

Expand Down Expand Up @@ -261,9 +267,26 @@ export class Tabs extends Ion implements AfterViewInit, RootNode, ITabs {
viewCtrl._setContent(this);
viewCtrl._setContentRef(elementRef);
}

if (keyboard) {
keyboard.didChange.subscribe((visible: boolean) => {
// TODO: this is a hacky implementation
// debouncing should be properly implemented in the native side
if (visible) {
this._tabbarHidden = visible;
this.resize();
} else {
setTimeout(() => {
this._tabbarHidden = visible;
this.resize();
}, 100);
}
});
}
}

ngOnDestroy() {
this._keyboardObs && this._keyboardObs.unsubscribe();
this._resizeObs && this._resizeObs.unsubscribe();
this.parent.unregisterChildNav(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<p><button ion-button (click)="color = !color" [color]="color ? 'primary':'secondary'">Change color</button></p>
<p>"Change color" should continue working after clicking Logout in the tabbar and cancelling (No in the alert)</p>
<p>UserId: {{userId}}</p>
<p><ion-input></ion-input></p>
<div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div>
<div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div><div f></div>

Expand Down
47 changes: 25 additions & 22 deletions src/platform/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,39 @@ export class Keyboard {
this.focusOutline(config.get('focusOutline'));

const win = <any>_plt.win();
const usingIonicEngine = win.Ionic && win.Ionic.KeyboardEvents === true;
if (usingIonicEngine) {
this.listenV2(win);
} else {
this.listenV1(win);
}
// const usingIonicEngine = win.Ionic && win.Ionic.KeyboardEvents === true;
// if (usingIonicEngine) {
// this.listenV2(win);
// } else {
// this.listenV1(win);
// }
this.listenV2(win);
}

private listenV2(win: any) {
this._plt.registerListener(win, 'native.ionic.keyboardWillShow', () => {
this.willShow.emit();
}, { zone: true, passive: true });
this._plt.registerListener(win, 'keyboardWillShow', () => {
this._zone.run(() => this.willShow.emit());
}, { zone: false, passive: true });

this._plt.registerListener(win, 'native.ionic.keyboardWillHide', () => {
this.willHide.emit();
this._plt.registerListener(win, 'keyboardWillHide', () => {
this._zone.run(() => {
this.willHide.emit();
this.didChange.emit(false);
});
this._plt.focusOutActiveElement();
}, { zone: true, passive: true });
}, { zone: false, passive: true });

this._plt.registerListener(win, 'native.ionic.keyboardDidShow', () => {
this.didShow.emit();
this.didChange.emit(true);
}, { zone: true, passive: true });
this._plt.registerListener(win, 'keyboardDidShow', () => {
this._zone.run(() => {
this.didShow.emit();
this.didChange.emit(true);
});
}, { zone: false, passive: true });

this._plt.registerListener(win, 'native.ionic.keyboardDidHide', () => {
this.didHide.emit();
this.didChange.emit(false);
}, { zone: true, passive: true });
this._plt.registerListener(win, 'keyboardDidHide', () => {
this._zone.run(() => this.didHide.emit());
}, { zone: false, passive: true });
this.eventsAvailable = true;


}

// TODO: deprecate once ionic-engine is released
Expand Down
4 changes: 2 additions & 2 deletions src/platform/platform-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export const PLATFORM_CONFIGS: { [key: string]: PlatformConfig } = {
};

function keyboardResizes(plt: Platform): boolean {
const win = <any>plt.win;
if (win.Ionic && win.Ionic.KeyboardResizes === true) {
const win = <any>plt.win();
if (win.Ionic && win.Ionic.keyboardResizes === true) {
return true;
}
return false;
Expand Down

1 comment on commit 09666bb

@AngelaRg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"hide tabbar when keyboard opens" ..is there a date established for when this fix will be integrated and available to use?

Please sign in to comment.