mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Compare commits
4 Commits
sp/pnpm-re
...
sp/FW-5486
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a413c1e3e | ||
|
|
7a097d9864 | ||
|
|
6a9fe5b2c1 | ||
|
|
d418bb2f9f |
@@ -1,7 +1,12 @@
|
|||||||
import { DOCUMENT } from '@angular/common';
|
import { DOCUMENT } from '@angular/common';
|
||||||
import { NgZone, Inject, Injectable } from '@angular/core';
|
import { NgZone, Inject } from '@angular/core';
|
||||||
import { getPlatforms, isPlatform } from '@ionic/core/components';
|
import type {
|
||||||
import type { BackButtonEventDetail, KeyboardEventDetail, Platforms } from '@ionic/core/components';
|
getPlatforms as _getPlatforms,
|
||||||
|
isPlatform as _isPlatform,
|
||||||
|
BackButtonEventDetail,
|
||||||
|
KeyboardEventDetail,
|
||||||
|
Platforms,
|
||||||
|
} from '@ionic/core/components';
|
||||||
import { Subscription, Subject } from 'rxjs';
|
import { Subscription, Subject } from 'rxjs';
|
||||||
|
|
||||||
// TODO(FW-2827): types
|
// TODO(FW-2827): types
|
||||||
@@ -13,9 +18,6 @@ export interface BackButtonEmitter extends Subject<BackButtonEventDetail> {
|
|||||||
): Subscription;
|
): Subscription;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root',
|
|
||||||
})
|
|
||||||
export class Platform {
|
export class Platform {
|
||||||
private _readyPromise: Promise<string>;
|
private _readyPromise: Promise<string>;
|
||||||
private win: any;
|
private win: any;
|
||||||
@@ -59,7 +61,12 @@ export class Platform {
|
|||||||
*/
|
*/
|
||||||
resize = new Subject<void>();
|
resize = new Subject<void>();
|
||||||
|
|
||||||
constructor(@Inject(DOCUMENT) private doc: any, zone: NgZone) {
|
constructor(
|
||||||
|
@Inject(DOCUMENT) protected doc: any,
|
||||||
|
zone: NgZone,
|
||||||
|
private isPlatform: typeof _isPlatform,
|
||||||
|
private getPlatforms: typeof _getPlatforms
|
||||||
|
) {
|
||||||
zone.run(() => {
|
zone.run(() => {
|
||||||
this.win = doc.defaultView;
|
this.win = doc.defaultView;
|
||||||
this.backButton.subscribeWithPriority = function (priority, callback) {
|
this.backButton.subscribeWithPriority = function (priority, callback) {
|
||||||
@@ -138,7 +145,7 @@ export class Platform {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
is(platformName: Platforms): boolean {
|
is(platformName: Platforms): boolean {
|
||||||
return isPlatform(this.win, platformName);
|
return this.isPlatform(this.win, platformName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -161,7 +168,7 @@ export class Platform {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
platforms(): string[] {
|
platforms(): string[] {
|
||||||
return getPlatforms(this.win);
|
return this.getPlatforms(this.win);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ export {
|
|||||||
DomController,
|
DomController,
|
||||||
NavController,
|
NavController,
|
||||||
Config,
|
Config,
|
||||||
Platform,
|
|
||||||
AngularDelegate,
|
AngularDelegate,
|
||||||
NavParams,
|
NavParams,
|
||||||
IonicRouteStrategy,
|
IonicRouteStrategy,
|
||||||
@@ -42,6 +41,7 @@ export {
|
|||||||
ViewDidLeave,
|
ViewDidLeave,
|
||||||
} from '@ionic/angular/common';
|
} from '@ionic/angular/common';
|
||||||
export { MenuController } from './providers/menu-controller';
|
export { MenuController } from './providers/menu-controller';
|
||||||
|
export { Platform } from './providers/platform';
|
||||||
|
|
||||||
// PACKAGE MODULE
|
// PACKAGE MODULE
|
||||||
export { IonicModule } from './ionic-module';
|
export { IonicModule } from './ionic-module';
|
||||||
|
|||||||
13
packages/angular/src/providers/platform.ts
Normal file
13
packages/angular/src/providers/platform.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
import { 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ export { IonRouterLink, IonRouterLinkWithHref } from './navigation/router-link-d
|
|||||||
export { IonTabs } from './navigation/tabs';
|
export { IonTabs } from './navigation/tabs';
|
||||||
export { provideIonicAngular } from './providers/ionic-angular';
|
export { provideIonicAngular } from './providers/ionic-angular';
|
||||||
export { MenuController } from './providers/menu-controller';
|
export { MenuController } from './providers/menu-controller';
|
||||||
|
export { Platform } from './providers/platform';
|
||||||
export {
|
export {
|
||||||
ActionSheetController,
|
ActionSheetController,
|
||||||
AlertController,
|
AlertController,
|
||||||
@@ -19,7 +20,6 @@ export {
|
|||||||
DomController,
|
DomController,
|
||||||
NavController,
|
NavController,
|
||||||
Config,
|
Config,
|
||||||
Platform,
|
|
||||||
NavParams,
|
NavParams,
|
||||||
IonicRouteStrategy,
|
IonicRouteStrategy,
|
||||||
ViewWillEnter,
|
ViewWillEnter,
|
||||||
|
|||||||
13
packages/angular/standalone/src/providers/platform.ts
Normal file
13
packages/angular/standalone/src/providers/platform.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
import { 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,3 +9,17 @@ describe('Providers', () => {
|
|||||||
cy.get('#keyboard-height').should('have.text', '12345');
|
cy.get('#keyboard-height').should('have.text', '12345');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe('Providers: Platform', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.visit('/standalone/providers/platform');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isReady should be true', () => {
|
||||||
|
cy.ionPageVisible('app-platform');
|
||||||
|
|
||||||
|
cy.get('#is-ready').should('have.text', 'true');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export const routes: Routes = [
|
|||||||
{ path: 'router-link', loadComponent: () => import('../router-link/router-link.component').then(c => c.RouterLinkComponent) },
|
{ path: 'router-link', loadComponent: () => import('../router-link/router-link.component').then(c => c.RouterLinkComponent) },
|
||||||
{ path: 'nav', loadComponent: () => import('../nav/nav.component').then(c => c.NavComponent) },
|
{ path: 'nav', loadComponent: () => import('../nav/nav.component').then(c => c.NavComponent) },
|
||||||
{ path: 'providers', loadComponent: () => import('../providers/providers.component').then(c => c.ProvidersComponent) },
|
{ path: 'providers', loadComponent: () => import('../providers/providers.component').then(c => c.ProvidersComponent) },
|
||||||
|
{ path: 'providers/platform', loadComponent: () => import('../platform/platform.component').then(c => c.PlatformComponent) },
|
||||||
{ path: 'overlay-controllers', loadComponent: () => import('../overlay-controllers/overlay-controllers.component').then(c => c.OverlayControllersComponent) },
|
{ path: 'overlay-controllers', loadComponent: () => import('../overlay-controllers/overlay-controllers.component').then(c => c.OverlayControllersComponent) },
|
||||||
{ path: 'button', loadComponent: () => import('../button/button.component').then(c => c.ButtonComponent) },
|
{ path: 'button', loadComponent: () => import('../button/button.component').then(c => c.ButtonComponent) },
|
||||||
{ path: 'icon', loadComponent: () => import('../icon/icon.component').then(c => c.IconComponent) },
|
{ path: 'icon', loadComponent: () => import('../icon/icon.component').then(c => c.IconComponent) },
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
isReady: <span id="is-ready">{{ isReady }}</span>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
isResumed: <span id="is-resumed">{{ isResumed }}</span>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
isPaused: <span id="is-paused">{{ isPaused }}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { Component, NgZone } from "@angular/core";
|
||||||
|
|
||||||
|
import { Platform } from '@ionic/angular/standalone';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: "app-platform",
|
||||||
|
templateUrl: "./platform.component.html",
|
||||||
|
standalone: true
|
||||||
|
})
|
||||||
|
export class PlatformComponent {
|
||||||
|
|
||||||
|
isReady = false;
|
||||||
|
isResumed = false;
|
||||||
|
isPaused = false;
|
||||||
|
isResized = false;
|
||||||
|
|
||||||
|
constructor(public platform: Platform) {
|
||||||
|
platform.ready().then(() => {
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isReady = true;
|
||||||
|
});
|
||||||
|
platform.resume.subscribe(() => {
|
||||||
|
console.log('platform:resume');
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isResumed = true;
|
||||||
|
});
|
||||||
|
platform.pause.subscribe(() => {
|
||||||
|
console.log('platform:pause');
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isPaused = true;
|
||||||
|
});
|
||||||
|
platform.resize.subscribe(() => {
|
||||||
|
console.log('platform:resize');
|
||||||
|
NgZone.assertInAngularZone();
|
||||||
|
this.isResized = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user