Skip to content

Commit bd4a295

Browse files
authored
Merge pull request #2375 from dpalou/MOBILE-3422
Mobile 3422
2 parents 180f99e + 9c11e75 commit bd4a295

File tree

5 files changed

+91
-11
lines changed

5 files changed

+91
-11
lines changed

src/components/ion-tabs/ion-tabs.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ion-app.app-root core-ion-tabs {
4444
}
4545
}
4646

47-
.tabbar[hidden] + .tabcontent {
47+
.tabbar[hidden] + .tabcontent, &.tabbar-hidden .tabcontent {
4848
width: 100%;
4949
core-ion-tab {
5050
@include position(0, 0, 0, 0);

src/components/ion-tabs/ion-tabs.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,11 @@ export class CoreIonTabsComponent extends Tabs implements OnDestroy {
388388
}
389389
}
390390
}
391+
392+
/**
393+
* @inheritdoc
394+
*/
395+
setTabbarHidden(tabbarHidden: boolean): void {
396+
// Don't hide the tab bar, we'll do it via CSS if needed.
397+
}
391398
}

src/core/mainmenu/pages/menu/menu.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Component, OnDestroy, ViewChild, ChangeDetectorRef } from '@angular/core';
16-
import { IonicPage, NavController, NavParams } from 'ionic-angular';
16+
import { IonicPage, NavController, NavParams, Platform } from 'ionic-angular';
1717
import { CoreAppProvider } from '@providers/app';
1818
import { CoreSitesProvider } from '@providers/sites';
1919
import { CoreEventsProvider } from '@providers/events';
@@ -45,13 +45,21 @@ export class CoreMainMenuPage implements OnDestroy {
4545
protected pendingRedirect: any;
4646
protected urlToOpen: string;
4747
protected mainMenuId: number;
48+
protected keyboardObserver: any;
4849

4950
@ViewChild('mainTabs') mainTabs: CoreIonTabsComponent;
5051

51-
constructor(private menuDelegate: CoreMainMenuDelegate, private sitesProvider: CoreSitesProvider, navParams: NavParams,
52-
private navCtrl: NavController, private eventsProvider: CoreEventsProvider, private cdr: ChangeDetectorRef,
53-
private mainMenuProvider: CoreMainMenuProvider, private linksDelegate: CoreContentLinksDelegate,
54-
private linksHelper: CoreContentLinksHelperProvider, private appProvider: CoreAppProvider) {
52+
constructor(protected menuDelegate: CoreMainMenuDelegate,
53+
protected sitesProvider: CoreSitesProvider,
54+
navParams: NavParams,
55+
protected navCtrl: NavController,
56+
protected eventsProvider: CoreEventsProvider,
57+
protected cdr: ChangeDetectorRef,
58+
protected mainMenuProvider: CoreMainMenuProvider,
59+
protected linksDelegate: CoreContentLinksDelegate,
60+
protected linksHelper: CoreContentLinksHelperProvider,
61+
protected appProvider: CoreAppProvider,
62+
protected platform: Platform) {
5563

5664
this.mainMenuId = this.appProvider.getMainMenuId();
5765

@@ -110,6 +118,21 @@ export class CoreMainMenuPage implements OnDestroy {
110118

111119
window.addEventListener('resize', this.initHandlers.bind(this));
112120

121+
if (this.platform.is('ios')) {
122+
// In iOS, the resize event is triggered before the keyboard is opened/closed and not triggered again once done.
123+
// Init handlers again once keyboard is closed since the resize event doesn't have the updated height.
124+
this.keyboardObserver = this.eventsProvider.on(CoreEventsProvider.KEYBOARD_CHANGE, (kbHeight) => {
125+
if (kbHeight === 0) {
126+
this.initHandlers();
127+
128+
// If the device is slow it can take a bit more to update the window height. Retry in a few ms.
129+
setTimeout(() => {
130+
this.initHandlers();
131+
}, 250);
132+
}
133+
});
134+
}
135+
113136
this.appProvider.setMainMenuOpen(this.mainMenuId, true);
114137
}
115138

@@ -221,5 +244,6 @@ export class CoreMainMenuPage implements OnDestroy {
221244
this.redirectObs && this.redirectObs.off();
222245
window.removeEventListener('resize', this.initHandlers.bind(this));
223246
this.appProvider.setMainMenuOpen(this.mainMenuId, false);
247+
this.keyboardObserver && this.keyboardObserver.off();
224248
}
225249
}

src/core/mainmenu/providers/mainmenu.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { Injectable } from '@angular/core';
1616
import { NavController } from 'ionic-angular';
17+
import { CoreApp } from '@providers/app';
1718
import { CoreLangProvider } from '@providers/lang';
1819
import { CoreSitesProvider } from '@providers/sites';
1920
import { CoreUtilsProvider } from '@providers/utils/utils';
@@ -54,8 +55,10 @@ export class CoreMainMenuProvider {
5455
static ITEM_MIN_WIDTH = 72; // Min with of every item, based on 5 items on a 360 pixel wide screen.
5556
protected tablet = false;
5657

57-
constructor(private langProvider: CoreLangProvider, private sitesProvider: CoreSitesProvider,
58-
protected menuDelegate: CoreMainMenuDelegate, protected utils: CoreUtilsProvider) {
58+
constructor(protected langProvider: CoreLangProvider,
59+
protected sitesProvider: CoreSitesProvider,
60+
protected menuDelegate: CoreMainMenuDelegate,
61+
protected utils: CoreUtilsProvider) {
5962
this.tablet = window && window.innerWidth && window.innerWidth >= 576 && window.innerHeight >= 576;
6063
}
6164

@@ -219,7 +222,8 @@ export class CoreMainMenuProvider {
219222
* @return Tabs placement including side value.
220223
*/
221224
getTabPlacement(navCtrl: NavController): string {
222-
const tablet = window && window.innerWidth && window.innerWidth >= 576 && window.innerHeight >= 576;
225+
const tablet = window && window.innerWidth && window.innerWidth >= 576 && (window.innerHeight >= 576 ||
226+
((CoreApp.instance.isKeyboardVisible() || CoreApp.instance.isKeyboardOpening()) && window.innerHeight >= 200));
223227

224228
if (tablet != this.tablet) {
225229
this.tablet = tablet;

src/providers/app.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export class CoreAppProvider {
143143
protected logger;
144144
protected ssoAuthenticationPromise: Promise<any>;
145145
protected isKeyboardShown = false;
146+
protected _isKeyboardOpening = false;
147+
protected _isKeyboardClosing = false;
146148
protected backActions = [];
147149
protected mainMenuId = 0;
148150
protected mainMenuOpen: number;
@@ -179,7 +181,7 @@ export class CoreAppProvider {
179181
// Execute the callback in the Angular zone, so change detection doesn't stop working.
180182
zone.run(() => {
181183
document.body.classList.add('keyboard-is-open');
182-
this.isKeyboardShown = true;
184+
this.setKeyboardShown(true);
183185
// Error on iOS calculating size.
184186
// More info: https://github.com/ionic-team/ionic-plugin-keyboard/issues/276 .
185187
events.trigger(CoreEventsProvider.KEYBOARD_CHANGE, data.keyboardHeight);
@@ -189,10 +191,24 @@ export class CoreAppProvider {
189191
// Execute the callback in the Angular zone, so change detection doesn't stop working.
190192
zone.run(() => {
191193
document.body.classList.remove('keyboard-is-open');
192-
this.isKeyboardShown = false;
194+
this.setKeyboardShown(false);
193195
events.trigger(CoreEventsProvider.KEYBOARD_CHANGE, 0);
194196
});
195197
});
198+
this.keyboard.onKeyboardWillShow().subscribe((data) => {
199+
// Execute the callback in the Angular zone, so change detection doesn't stop working.
200+
zone.run(() => {
201+
this._isKeyboardOpening = true;
202+
this._isKeyboardClosing = false;
203+
});
204+
});
205+
this.keyboard.onKeyboardWillHide().subscribe((data) => {
206+
// Execute the callback in the Angular zone, so change detection doesn't stop working.
207+
zone.run(() => {
208+
this._isKeyboardOpening = false;
209+
this._isKeyboardClosing = true;
210+
});
211+
});
196212

197213
this.platform.registerBackButtonAction(() => {
198214
this.backButtonAction();
@@ -387,6 +403,24 @@ export class CoreAppProvider {
387403
return this.platform.is('ios');
388404
}
389405

406+
/**
407+
* Check if the keyboard is closing.
408+
*
409+
* @return Whether keyboard is closing (animating).
410+
*/
411+
isKeyboardClosing(): boolean {
412+
return this._isKeyboardClosing;
413+
}
414+
415+
/**
416+
* Check if the keyboard is being opened.
417+
*
418+
* @return Whether keyboard is opening (animating).
419+
*/
420+
isKeyboardOpening(): boolean {
421+
return this._isKeyboardOpening;
422+
}
423+
390424
/**
391425
* Check if the keyboard is visible.
392426
*
@@ -529,6 +563,17 @@ export class CoreAppProvider {
529563
}
530564
}
531565

566+
/**
567+
* Set keyboard shown or hidden.
568+
*
569+
* @param Whether the keyboard is shown or hidden.
570+
*/
571+
protected setKeyboardShown(shown: boolean): void {
572+
this.isKeyboardShown = shown;
573+
this._isKeyboardOpening = false;
574+
this._isKeyboardClosing = false;
575+
}
576+
532577
/**
533578
* Set a main menu as open or not.
534579
*

0 commit comments

Comments
 (0)