refactor(angular): platform uses correct core instance

This commit is contained in:
Sean Perkins
2023-11-06 15:17:03 -05:00
parent dfafb27435
commit d418bb2f9f
5 changed files with 42 additions and 11 deletions

View File

@@ -1,7 +1,12 @@
import { DOCUMENT } from '@angular/common';
import { NgZone, Inject, Injectable } from '@angular/core';
import { getPlatforms, isPlatform } from '@ionic/core/components';
import type { BackButtonEventDetail, KeyboardEventDetail, Platforms } from '@ionic/core/components';
import { NgZone, Inject } from '@angular/core';
import type {
getPlatforms as _getPlatforms,
isPlatform as _isPlatform,
BackButtonEventDetail,
KeyboardEventDetail,
Platforms,
} from '@ionic/core/components';
import { Subscription, Subject } from 'rxjs';
// TODO(FW-2827): types
@@ -13,9 +18,6 @@ export interface BackButtonEmitter extends Subject<BackButtonEventDetail> {
): Subscription;
}
@Injectable({
providedIn: 'root',
})
export class Platform {
private _readyPromise: Promise<string>;
private win: any;
@@ -59,7 +61,12 @@ export class Platform {
*/
resize = new Subject<void>();
constructor(@Inject(DOCUMENT) private doc: any, zone: NgZone) {
constructor(
@Inject(DOCUMENT) private doc: any,
zone: NgZone,
private isPlatform: typeof _isPlatform,
private getPlatforms: typeof _getPlatforms
) {
zone.run(() => {
this.win = doc.defaultView;
this.backButton.subscribeWithPriority = function (priority, callback) {
@@ -138,7 +145,7 @@ export class Platform {
*
*/
is(platformName: Platforms): boolean {
return isPlatform(this.win, platformName);
return this.isPlatform(this.win, platformName);
}
/**
@@ -161,7 +168,7 @@ export class Platform {
* ```
*/
platforms(): string[] {
return getPlatforms(this.win);
return this.getPlatforms(this.win);
}
/**

View File

@@ -32,7 +32,6 @@ export {
DomController,
NavController,
Config,
Platform,
AngularDelegate,
NavParams,
IonicRouteStrategy,
@@ -42,6 +41,7 @@ export {
ViewDidLeave,
} from '@ionic/angular/common';
export { MenuController } from './providers/menu-controller';
export { Platform } from './providers/platform';
// PACKAGE MODULE
export { IonicModule } from './ionic-module';

View File

@@ -0,0 +1,12 @@
import { DOCUMENT, Injectable, NgZone, Inject } from '@angular/core';
import { Platform as PlatformBase } from '@ionic/angular/common';
import { isPlatform, getPlatforms } from '@ionic/core';
@Injectable({
providedIn: 'root',
})
export class Platform extends PlatformBase {
constructor(@Inject(DOCUMENT) protected doc: any, zone: NgZone) {
super(doc, zone, isPlatform, getPlatforms);
}
}

View File

@@ -6,6 +6,7 @@ export { IonRouterLink, IonRouterLinkWithHref } from './navigation/router-link-d
export { IonTabs } from './navigation/tabs';
export { provideIonicAngular } from './providers/ionic-angular';
export { MenuController } from './providers/menu-controller';
export { Platform } from './providers/platform';
export {
ActionSheetController,
AlertController,
@@ -19,7 +20,6 @@ export {
DomController,
NavController,
Config,
Platform,
NavParams,
IonicRouteStrategy,
ViewWillEnter,

View File

@@ -0,0 +1,12 @@
import { DOCUMENT, Injectable, NgZone, Inject } from '@angular/core';
import { Platform as PlatformBase } from '@ionic/angular/common';
import { isPlatform, getPlatforms } from '@ionic/core/components';
@Injectable({
providedIn: 'root',
})
export class Platform extends PlatformBase {
constructor(@Inject(DOCUMENT) protected doc: any, zone: NgZone) {
super(doc, zone, isPlatform, getPlatforms);
}
}