Skip to content
Open
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
16 changes: 13 additions & 3 deletions packages/angular/common/src/providers/platform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DOCUMENT } from '@angular/common';
import { NgZone, Inject, Injectable } from '@angular/core';
import type { DestroyRef } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { getPlatforms, isPlatform } from '@ionic/core/components';
import type { BackButtonEventDetail, KeyboardEventDetail, Platforms } from '@ionic/core/components';
import { Subscription, Subject } from 'rxjs';
Expand All @@ -9,7 +11,13 @@ import { Subscription, Subject } from 'rxjs';
export interface BackButtonEmitter extends Subject<BackButtonEventDetail> {
subscribeWithPriority(
priority: number,
callback: (processNextHandler: () => void) => Promise<any> | void
callback: (processNextHandler: () => void) => Promise<any> | void,
/**
* Pass a component's `DestroyRef` to have the subscription torn down with that
* component. Without it the subscription lives for the lifetime of the injector,
* which for a root-provided `Platform` means the lifetime of the application.
*/
destroyRef?: DestroyRef
): Subscription;
}

Expand Down Expand Up @@ -62,8 +70,10 @@ export class Platform {
constructor(@Inject(DOCUMENT) private doc: any, zone: NgZone) {
zone.run(() => {
this.win = doc.defaultView;
this.backButton.subscribeWithPriority = function (priority, callback) {
return this.subscribe((ev) => {
this.backButton.subscribeWithPriority = function (priority, callback, destroyRef) {
const source$ = destroyRef ? this.pipe(takeUntilDestroyed(destroyRef)) : this;

return source$.subscribe((ev) => {
return ev.register(priority, (processNextHandler) => zone.run(() => callback(processNextHandler)));
});
};
Expand Down