Merge pull request #2494 from dpalou/MOBILE-3511

MOBILE-3511 splitview: Fix some events not triggered in right view
main
Juan Leyva 2020-09-08 16:20:01 +02:00 committed by GitHub
commit 994120b3b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 5 deletions

View File

@ -194,6 +194,11 @@ export class AddonModForumDiscussionPage implements OnDestroy {
* User entered the page that contains the component. * User entered the page that contains the component.
*/ */
ionViewDidEnter(): void { ionViewDidEnter(): void {
if (this.syncObserver) {
// Already setup.
return;
}
// Refresh data if this discussion is synchronized automatically. // Refresh data if this discussion is synchronized automatically.
this.syncObserver = this.eventsProvider.on(AddonModForumSyncProvider.AUTO_SYNCED, (data) => { this.syncObserver = this.eventsProvider.on(AddonModForumSyncProvider.AUTO_SYNCED, (data) => {
if (data.forumId == this.forumId && this.discussionId == data.discussionId if (data.forumId == this.forumId && this.discussionId == data.discussionId
@ -706,6 +711,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.ratingOfflineObserver && this.ratingOfflineObserver.off(); this.ratingOfflineObserver && this.ratingOfflineObserver.off();
this.ratingSyncObserver && this.ratingSyncObserver.off(); this.ratingSyncObserver && this.ratingSyncObserver.off();
this.changeDiscObserver && this.changeDiscObserver.off(); this.changeDiscObserver && this.changeDiscObserver.off();
delete this.syncObserver;
} }
/** /**

View File

@ -112,6 +112,11 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
* User entered the page that contains the component. * User entered the page that contains the component.
*/ */
ionViewDidEnter(): void { ionViewDidEnter(): void {
if (this.syncObserver) {
// Already setup.
return;
}
// Refresh data if this discussion is synchronized automatically. // Refresh data if this discussion is synchronized automatically.
this.syncObserver = this.eventsProvider.on(AddonModForumSyncProvider.AUTO_SYNCED, (data) => { this.syncObserver = this.eventsProvider.on(AddonModForumSyncProvider.AUTO_SYNCED, (data) => {
if (data.forumId == this.forumId && data.userId == this.sitesProvider.getCurrentSiteUserId()) { if (data.forumId == this.forumId && data.userId == this.sitesProvider.getCurrentSiteUserId()) {
@ -549,6 +554,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
*/ */
ionViewWillLeave(): void { ionViewWillLeave(): void {
this.syncObserver && this.syncObserver.off(); this.syncObserver && this.syncObserver.off();
delete this.syncObserver;
} }
/** /**

View File

@ -49,18 +49,20 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
@ViewChild('menu') menu: Menu; @ViewChild('menu') menu: Menu;
@Input() when?: string | boolean = 'md'; @Input() when?: string | boolean = 'md';
protected VIEW_EVENTS = ['willEnter', 'didEnter', 'willLeave', 'willLeave'];
protected isEnabled; protected isEnabled;
protected masterPageName = ''; protected masterPageName = '';
protected masterPageIndex = 0; protected masterPageIndex = 0;
protected loadDetailPage: any = false; protected loadDetailPage: any = false;
protected element: HTMLElement; // Current element. protected element: HTMLElement; // Current element.
protected detailsDidEnterSubscription: Subscription;
protected masterCanLeaveOverridden = false; protected masterCanLeaveOverridden = false;
protected originalMasterCanLeave: Function; protected originalMasterCanLeave: Function;
protected ignoreSplitChanged = false; protected ignoreSplitChanged = false;
protected audioCaptureSubscription: Subscription; protected audioCaptureSubscription: Subscription;
protected languageChangedSubscription: Subscription; protected languageChangedSubscription: Subscription;
protected pushOngoing: boolean; protected pushOngoing: boolean;
protected viewEventsSubscriptions: Subscription[] = [];
// Empty placeholder for the 'detail' page. // Empty placeholder for the 'detail' page.
detailPage: any = null; detailPage: any = null;
@ -92,7 +94,7 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
this.masterPageIndex = this.masterNav.indexOf(this.masterNav.getActive()); this.masterPageIndex = this.masterNav.indexOf(this.masterNav.getActive());
this.emptyDetails(); this.emptyDetails();
this.handleCanLeave(); this.handleViewEvents();
} }
/** /**
@ -123,7 +125,7 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
*/ */
handleCanLeave(): void { handleCanLeave(): void {
// Listen for the didEnter event on the details nav to detect everytime a page is loaded. // Listen for the didEnter event on the details nav to detect everytime a page is loaded.
this.detailsDidEnterSubscription = this.detailNav.viewDidEnter.subscribe((detailsViewController: ViewController) => { this.viewEventsSubscriptions.push(this.detailNav.viewDidEnter.subscribe((detailsViewController: ViewController) => {
if (!this.isOn()) { if (!this.isOn()) {
return; return;
} }
@ -166,7 +168,30 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
}); });
}; };
} }
}); }));
}
/**
* Handle Ionic Views lifecycle events in the details page.
*/
handleViewEvents(): void {
// Handle affected view events except ionViewCanLeave, propagating them to the details view.
const masterActiveView = this.masterNav.getActive();
for (const i in this.VIEW_EVENTS) {
const viewEvent = this.VIEW_EVENTS[i];
this.viewEventsSubscriptions.push(masterActiveView[viewEvent].subscribe(() => {
if (!this.isOn()) {
return;
}
const activeView = this.detailNav.getActive();
activeView && activeView[`_${viewEvent}`]();
}));
}
this.handleCanLeave();
} }
/** /**
@ -274,8 +299,10 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
* Component being destroyed. * Component being destroyed.
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.detailsDidEnterSubscription && this.detailsDidEnterSubscription.unsubscribe();
this.audioCaptureSubscription.unsubscribe(); this.audioCaptureSubscription.unsubscribe();
this.languageChangedSubscription.unsubscribe(); this.languageChangedSubscription.unsubscribe();
for (const i in this.viewEventsSubscriptions) {
this.viewEventsSubscriptions[i].unsubscribe();
}
} }
} }