From b47a373382cfa2e42b97e81a3083babe434b592a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 20 Nov 2018 13:52:28 +0100 Subject: [PATCH] MOBILE-2676 ux: Fix top margin when rotating --- src/app/app.component.ts | 3 ++- src/app/app.module.ts | 48 +++++++++++++++++++++++++++++++++++++++- src/providers/events.ts | 1 + 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 2c4340790..fb53313e6 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -185,8 +185,9 @@ export class MoodleMobileApp implements OnInit { viewport.setAttribute('content', 'viewport-fit=cover,' + viewport.getAttribute('content')); }); } + + this.eventsProvider.trigger(CoreEventsProvider.ORIENTATION_CHANGE); } ); - } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 634219ac4..83003549f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -286,7 +286,7 @@ export const CORE_PROVIDERS: any[] = [ }) export class AppModule { constructor(platform: Platform, initDelegate: CoreInitDelegate, updateManager: CoreUpdateManagerProvider, config: Config, - sitesProvider: CoreSitesProvider, fileProvider: CoreFileProvider) { + sitesProvider: CoreSitesProvider, fileProvider: CoreFileProvider, private eventsProvider: CoreEventsProvider) { // Register a handler for platform ready. initDelegate.registerProcess({ name: 'CorePlatformReady', @@ -484,5 +484,51 @@ export class AppModule { // Initial imgs refresh. this.imgsUpdate(); }; + + const eventsProvider = this.eventsProvider; + + // tslint:disable: typedef + ( Content).prototype.ngAfterViewInit = function() { + assert(this.getFixedElement(), 'fixed element was not found'); + assert(this.getScrollElement(), 'scroll element was not found'); + + const scroll = this._scroll; + scroll.ev.fixedElement = this.getFixedElement(); + scroll.ev.scrollElement = this.getScrollElement(); + + // Subscribe to the scroll start + scroll.onScrollStart = (ev) => { + this.ionScrollStart.emit(ev); + }; + + // Subscribe to every scroll move + scroll.onScroll = (ev) => { + // Emit to all of our other friends things be scrolling + this.ionScroll.emit(ev); + + this.imgsUpdate(); + }; + + // Subscribe to the scroll end + scroll.onScrollEnd = (ev) => { + this.ionScrollEnd.emit(ev); + + this.imgsUpdate(); + }; + + // Recalculate size when screen rotates. + this._orientationObs = eventsProvider.on(CoreEventsProvider.ORIENTATION_CHANGE, this.resize.bind(this)); + }; + + // tslint:disable: typedef + ( Content).prototype.ngOnDestroy = function() { + this._scLsn && this._scLsn(); + this._viewCtrlReadSub && this._viewCtrlReadSub.unsubscribe(); + this._viewCtrlWriteSub && this._viewCtrlWriteSub.unsubscribe(); + this._viewCtrlReadSub = this._viewCtrlWriteSub = null; + this._scroll && this._scroll.destroy(); + this._footerEle = this._scLsn = this._scroll = null; + this._orientationObs && this._orientationObs.off(); + }; } } diff --git a/src/providers/events.ts b/src/providers/events.ts index 80764ed37..a523a7b8c 100644 --- a/src/providers/events.ts +++ b/src/providers/events.ts @@ -56,6 +56,7 @@ export class CoreEventsProvider { static FILE_SHARED = 'file_shared'; static KEYBOARD_CHANGE = 'keyboard_change'; static CORE_LOADING_CHANGED = 'core_loading_changed'; + static ORIENTATION_CHANGE = 'orientation_change'; protected logger; protected observables: { [s: string]: Subject } = {};