Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/addon/mod/forum/pages/discussion/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ export class AddonModForumDiscussionPage implements OnDestroy {
* User entered the page that contains the component.
*/
ionViewDidEnter(): void {
if (this.syncObserver) {
// Already setup.
return;
}

// Refresh data if this discussion is synchronized automatically.
this.syncObserver = this.eventsProvider.on(AddonModForumSyncProvider.AUTO_SYNCED, (data) => {
if (data.forumId == this.forumId && this.discussionId == data.discussionId
Expand Down Expand Up @@ -688,6 +693,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
this.ratingOfflineObserver && this.ratingOfflineObserver.off();
this.ratingSyncObserver && this.ratingSyncObserver.off();
this.changeDiscObserver && this.changeDiscObserver.off();
delete this.syncObserver;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/addon/mod/forum/pages/new-discussion/new-discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
* User entered the page that contains the component.
*/
ionViewDidEnter(): void {
if (this.syncObserver) {
// Already setup.
return;
}

// Refresh data if this discussion is synchronized automatically.
this.syncObserver = this.eventsProvider.on(AddonModForumSyncProvider.AUTO_SYNCED, (data) => {
if (data.forumId == this.forumId && data.userId == this.sitesProvider.getCurrentSiteUserId()) {
Expand Down Expand Up @@ -549,6 +554,7 @@ export class AddonModForumNewDiscussionPage implements OnDestroy {
*/
ionViewWillLeave(): void {
this.syncObserver && this.syncObserver.off();
delete this.syncObserver;
}

/**
Expand Down
37 changes: 32 additions & 5 deletions src/components/split-view/split-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
@ViewChild('menu') menu: Menu;
@Input() when?: string | boolean = 'md';

protected VIEW_EVENTS = ['willEnter', 'didEnter', 'willLeave', 'willLeave'];

protected isEnabled;
protected masterPageName = '';
protected masterPageIndex = 0;
protected loadDetailPage: any = false;
protected element: HTMLElement; // Current element.
protected detailsDidEnterSubscription: Subscription;
protected masterCanLeaveOverridden = false;
protected originalMasterCanLeave: Function;
protected ignoreSplitChanged = false;
protected audioCaptureSubscription: Subscription;
protected languageChangedSubscription: Subscription;
protected pushOngoing: boolean;
protected viewEventsSubscriptions: Subscription[] = [];

// Empty placeholder for the 'detail' page.
detailPage: any = null;
Expand Down Expand Up @@ -92,7 +94,7 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
this.masterPageIndex = this.masterNav.indexOf(this.masterNav.getActive());
this.emptyDetails();

this.handleCanLeave();
this.handleViewEvents();
}

/**
Expand Down Expand Up @@ -123,7 +125,7 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
*/
handleCanLeave(): void {
// 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()) {
return;
}
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -274,8 +299,10 @@ export class CoreSplitViewComponent implements OnInit, OnDestroy {
* Component being destroyed.
*/
ngOnDestroy(): void {
this.detailsDidEnterSubscription && this.detailsDidEnterSubscription.unsubscribe();
this.audioCaptureSubscription.unsubscribe();
this.languageChangedSubscription.unsubscribe();
for (const i in this.viewEventsSubscriptions) {
this.viewEventsSubscriptions[i].unsubscribe();
}
}
}