UNPKG

17 kBTypeScriptView Raw
1import { EventEmitter, NgZone } from '@angular/core';
2export declare type DocumentDirection = 'ltr' | 'rtl';
3/**
4 * @name Platform
5 * @description
6 * The Platform service can be used to get information about your current device.
7 * You can get all of the platforms associated with the device using the [platforms](#platforms)
8 * method, including whether the app is being viewed from a tablet, if it's
9 * on a mobile device or browser, and the exact platform (iOS, Android, etc).
10 * You can also get the orientation of the device, if it uses right-to-left
11 * language direction, and much much more. With this information you can completely
12 * customize your app to fit any device.
13 *
14 * @usage
15 * ```ts
16 * import { Platform } from 'ionic-angular';
17 *
18 * @Component({...})
19 * export MyPage {
20 * constructor(public platform: Platform) {
21 *
22 * }
23 * }
24 * ```
25 * @demo /docs/demos/src/platform/
26 */
27export declare class Platform {
28 private _win;
29 private _doc;
30 private _versions;
31 private _dir;
32 private _lang;
33 private _ua;
34 private _qp;
35 private _nPlt;
36 private _readyPromise;
37 private _readyResolve;
38 private _bbActions;
39 private _registry;
40 private _default;
41 private _pW;
42 private _pH;
43 private _lW;
44 private _lH;
45 private _isPortrait;
46 private _uiEvtOpts;
47 /** @hidden */
48 zone: NgZone;
49 /** @internal */
50 Css: {
51 transform?: string;
52 transition?: string;
53 transitionDuration?: string;
54 transitionDelay?: string;
55 transitionTimingFn?: string;
56 transitionStart?: string;
57 transitionEnd?: string;
58 transformOrigin?: string;
59 animationDelay?: string;
60 };
61 /** @internal */
62 _platforms: string[];
63 constructor();
64 /**
65 * @hidden
66 */
67 setWindow(win: Window): void;
68 /**
69 * @hidden
70 */
71 win(): Window;
72 /**
73 * @hidden
74 */
75 setDocument(doc: HTMLDocument): void;
76 /**
77 * @hidden
78 */
79 doc(): HTMLDocument;
80 /**
81 * @hidden
82 */
83 setZone(zone: NgZone): void;
84 /**
85 * @hidden
86 */
87 setCssProps(docElement: HTMLElement): void;
88 /**
89 * @returns {boolean} returns true/false based on platform.
90 * @description
91 * Depending on the platform the user is on, `is(platformName)` will
92 * return `true` or `false`. Note that the same app can return `true`
93 * for more than one platform name. For example, an app running from
94 * an iPad would return `true` for the platform names: `mobile`,
95 * `ios`, `ipad`, and `tablet`. Additionally, if the app was running
96 * from Cordova then `cordova` would be true, and if it was running
97 * from a web browser on the iPad then `mobileweb` would be `true`.
98 *
99 * ```
100 * import { Platform } from 'ionic-angular';
101 *
102 * @Component({...})
103 * export MyPage {
104 * constructor(public platform: Platform) {
105 * if (this.platform.is('ios')) {
106 * // This will only print when on iOS
107 * console.log('I am an iOS device!');
108 * }
109 * }
110 * }
111 * ```
112 *
113 * | Platform Name | Description |
114 * |-----------------|------------------------------------|
115 * | android | on a device running Android. |
116 * | cordova | on a device running Cordova. |
117 * | core | on a desktop device. |
118 * | ios | on a device running iOS. |
119 * | ipad | on an iPad device. |
120 * | iphone | on an iPhone device. |
121 * | mobile | on a mobile device. |
122 * | mobileweb | in a browser on a mobile device. |
123 * | phablet | on a phablet device. |
124 * | tablet | on a tablet device. |
125 * | windows | on a device running Windows. |
126 * | electron | in Electron on a desktop device. |
127 *
128 * @param {string} platformName
129 */
130 is(platformName: string): boolean;
131 /**
132 * @returns {array} the array of platforms
133 * @description
134 * Depending on what device you are on, `platforms` can return multiple values.
135 * Each possible value is a hierarchy of platforms. For example, on an iPhone,
136 * it would return `mobile`, `ios`, and `iphone`.
137 *
138 * ```
139 * import { Platform } from 'ionic-angular';
140 *
141 * @Component({...})
142 * export MyPage {
143 * constructor(public platform: Platform) {
144 * // This will print an array of the current platforms
145 * console.log(this.platform.platforms());
146 * }
147 * }
148 * ```
149 */
150 platforms(): Array<string>;
151 /**
152 * Returns an object containing version information about all of the platforms.
153 *
154 * ```
155 * import { Platform } from 'ionic-angular';
156 *
157 * @Component({...})
158 * export MyPage {
159 * constructor(public platform: Platform) {
160 * // This will print an object containing
161 * // all of the platforms and their versions
162 * console.log(platform.versions());
163 * }
164 * }
165 * ```
166 *
167 * @returns {object} An object containing all of the platforms and their versions.
168 */
169 versions(): {
170 [name: string]: PlatformVersion;
171 };
172 /**
173 * @hidden
174 */
175 version(): PlatformVersion;
176 /**
177 * Returns a promise when the platform is ready and native functionality
178 * can be called. If the app is running from within a web browser, then
179 * the promise will resolve when the DOM is ready. When the app is running
180 * from an application engine such as Cordova, then the promise will
181 * resolve when Cordova triggers the `deviceready` event.
182 *
183 * The resolved value is the `readySource`, which states which platform
184 * ready was used. For example, when Cordova is ready, the resolved ready
185 * source is `cordova`. The default ready source value will be `dom`. The
186 * `readySource` is useful if different logic should run depending on the
187 * platform the app is running from. For example, only Cordova can execute
188 * the status bar plugin, so the web should not run status bar plugin logic.
189 *
190 * ```
191 * import { Component } from '@angular/core';
192 * import { Platform } from 'ionic-angular';
193 *
194 * @Component({...})
195 * export MyApp {
196 * constructor(public platform: Platform) {
197 * this.platform.ready().then((readySource) => {
198 * console.log('Platform ready from', readySource);
199 * // Platform now ready, execute any required native code
200 * });
201 * }
202 * }
203 * ```
204 * @returns {promise}
205 */
206 ready(): Promise<string>;
207 /**
208 * @hidden
209 * This should be triggered by the engine when the platform is
210 * ready. If there was no custom prepareReady method from the engine,
211 * such as Cordova or Electron, then it uses the default DOM ready.
212 */
213 triggerReady(readySource: string): void;
214 /**
215 * @hidden
216 * This is the default prepareReady if it's not replaced by an engine,
217 * such as Cordova or Electron. If there was no custom prepareReady
218 * method from an engine then it uses the method below, which triggers
219 * the platform ready on the DOM ready event, and the default resolved
220 * value is `dom`.
221 */
222 prepareReady(): void;
223 /**
224 * Set the app's language direction, which will update the `dir` attribute
225 * on the app's root `<html>` element. We recommend the app's `index.html`
226 * file already has the correct `dir` attribute value set, such as
227 * `<html dir="ltr">` or `<html dir="rtl">`. This method is useful if the
228 * direction needs to be dynamically changed per user/session.
229 * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
230 * @param {DocumentDirection} dir Examples: `rtl`, `ltr`
231 * @param {boolean} updateDocument
232 */
233 setDir(dir: DocumentDirection, updateDocument: boolean): void;
234 /**
235 * Returns app's language direction.
236 * We recommend the app's `index.html` file already has the correct `dir`
237 * attribute value set, such as `<html dir="ltr">` or `<html dir="rtl">`.
238 * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
239 * @returns {DocumentDirection}
240 */
241 dir(): DocumentDirection;
242 /**
243 * Returns if this app is using right-to-left language direction or not.
244 * We recommend the app's `index.html` file already has the correct `dir`
245 * attribute value set, such as `<html dir="ltr">` or `<html dir="rtl">`.
246 * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
247 * @returns {boolean}
248 */
249 isRTL: boolean;
250 /**
251 * Set the app's language and optionally the country code, which will update
252 * the `lang` attribute on the app's root `<html>` element.
253 * We recommend the app's `index.html` file already has the correct `lang`
254 * attribute value set, such as `<html lang="en">`. This method is useful if
255 * the language needs to be dynamically changed per user/session.
256 * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations)
257 * @param {string} language Examples: `en-US`, `en-GB`, `ar`, `de`, `zh`, `es-MX`
258 * @param {boolean} updateDocument Specifies whether the `lang` attribute of `<html>` should be updated
259 */
260 setLang(language: string, updateDocument: boolean): void;
261 /**
262 * Returns app's language and optional country code.
263 * We recommend the app's `index.html` file already has the correct `lang`
264 * attribute value set, such as `<html lang="en">`.
265 * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations)
266 * @returns {string}
267 */
268 lang(): string;
269 /**
270 * @hidden
271 */
272 exitApp(): void;
273 /**
274 * @hidden
275 */
276 backButton: EventEmitter<Event>;
277 /**
278 * The pause event emits when the native platform puts the application
279 * into the background, typically when the user switches to a different
280 * application. This event would emit when a Cordova app is put into
281 * the background, however, it would not fire on a standard web browser.
282 */
283 pause: EventEmitter<Event>;
284 /**
285 * The resume event emits when the native platform pulls the application
286 * out from the background. This event would emit when a Cordova app comes
287 * out from the background, however, it would not fire on a standard web browser.
288 */
289 resume: EventEmitter<Event>;
290 /**
291 * The resize event emits when the browser window has changed dimensions. This
292 * could be from a browser window being physically resized, or from a device
293 * changing orientation.
294 */
295 resize: EventEmitter<Event>;
296 /**
297 * The back button event is triggered when the user presses the native
298 * platform's back button, also referred to as the "hardware" back button.
299 * This event is only used within Cordova apps running on Android and
300 * Windows platforms. This event is not fired on iOS since iOS doesn't come
301 * with a hardware back button in the same sense an Android or Windows device
302 * does.
303 *
304 * Registering a hardware back button action and setting a priority allows
305 * apps to control which action should be called when the hardware back
306 * button is pressed. This method decides which of the registered back button
307 * actions has the highest priority and should be called.
308 *
309 * @param {Function} fn Called when the back button is pressed,
310 * if this registered action has the highest priority.
311 * @param {number} priority Set the priority for this action. Only the highest priority will execute. Defaults to `0`.
312 * @returns {Function} A function that, when called, will unregister
313 * the back button action.
314 */
315 registerBackButtonAction(fn: Function, priority?: number): Function;
316 /**
317 * @hidden
318 */
319 runBackButtonAction(): void;
320 /**
321 * @hidden
322 */
323 setUserAgent(userAgent: string): void;
324 /**
325 * @hidden
326 */
327 setQueryParams(url: string): void;
328 /**
329 * Get the query string parameter
330 */
331 getQueryParam(key: string): any;
332 /**
333 * Get the current url.
334 */
335 url(): string;
336 /**
337 * @hidden
338 */
339 userAgent(): string;
340 /**
341 * @hidden
342 */
343 setNavigatorPlatform(navigatorPlt: string): void;
344 /**
345 * @hidden
346 */
347 navigatorPlatform(): string;
348 /**
349 * Gets the width of the platform's viewport using `window.innerWidth`.
350 * Using this method is preferred since the dimension is a cached value,
351 * which reduces the chance of multiple and expensive DOM reads.
352 */
353 width(): number;
354 /**
355 * Gets the height of the platform's viewport using `window.innerHeight`.
356 * Using this method is preferred since the dimension is a cached value,
357 * which reduces the chance of multiple and expensive DOM reads.
358 */
359 height(): number;
360 /**
361 * @hidden
362 */
363 getElementComputedStyle(ele: HTMLElement, pseudoEle?: string): CSSStyleDeclaration;
364 /**
365 * @hidden
366 */
367 getElementFromPoint(x: number, y: number): HTMLElement;
368 /**
369 * @hidden
370 */
371 getElementBoundingClientRect(ele: HTMLElement): ClientRect;
372 /**
373 * Returns `true` if the app is in portait mode.
374 */
375 isPortrait(): boolean;
376 /**
377 * Returns `true` if the app is in landscape mode.
378 */
379 isLandscape(): boolean;
380 private _calcDim();
381 /**
382 * @hidden
383 * This requestAnimationFrame will NOT be wrapped by zone.
384 */
385 raf(callback: {
386 (timeStamp?: number): void;
387 } | Function): number;
388 /**
389 * @hidden
390 */
391 cancelRaf(rafId: number): any;
392 /**
393 * @hidden
394 * This setTimeout will NOT be wrapped by zone.
395 */
396 timeout(callback: Function, timeout?: number): number;
397 /**
398 * @hidden
399 * This setTimeout will NOT be wrapped by zone.
400 */
401 cancelTimeout(timeoutId: number): void;
402 /**
403 * @hidden
404 * Built to use modern event listener options, like "passive".
405 * If options are not supported, then just return a boolean which
406 * represents "capture". Returns a method to remove the listener.
407 */
408 registerListener(ele: any, eventName: string, callback: {
409 (ev?: UIEvent): void;
410 }, opts: EventListenerOptions, unregisterListenersCollection?: Function[]): Function;
411 /**
412 * @hidden
413 */
414 transitionEnd(el: HTMLElement, callback: {
415 (ev?: TransitionEvent): void;
416 }, zone?: boolean): () => void;
417 /**
418 * @hidden
419 */
420 windowLoad(callback: Function): void;
421 /**
422 * @hidden
423 */
424 isActiveElement(ele: HTMLElement): boolean;
425 /**
426 * @hidden
427 */
428 getActiveElement(): Element;
429 /**
430 * @hidden
431 */
432 hasFocus(ele: HTMLElement): boolean;
433 /**
434 * @hidden
435 */
436 hasFocusedTextInput(): boolean;
437 /**
438 * @hidden
439 */
440 focusOutActiveElement(): void;
441 private _initEvents();
442 /**
443 * @hidden
444 */
445 setPlatformConfigs(platformConfigs: {
446 [key: string]: PlatformConfig;
447 }): void;
448 /**
449 * @hidden
450 */
451 getPlatformConfig(platformName: string): PlatformConfig;
452 /**
453 * @hidden
454 */
455 registry(): {
456 [name: string]: PlatformConfig;
457 };
458 /**
459 * @hidden
460 */
461 setDefault(platformName: string): void;
462 /**
463 * @hidden
464 */
465 testQuery(queryValue: string, queryTestValue: string): boolean;
466 /**
467 * @hidden
468 */
469 testNavigatorPlatform(navigatorPlatformExpression: string): boolean;
470 /**
471 * @hidden
472 */
473 matchUserAgentVersion(userAgentExpression: RegExp): any;
474 testUserAgent(expression: string): boolean;
475 /**
476 * @hidden
477 */
478 isPlatformMatch(queryStringName: string, userAgentAtLeastHas?: string[], userAgentMustNotHave?: string[]): boolean;
479 /** @hidden */
480 init(): void;
481 /**
482 * @hidden
483 */
484 private matchPlatform(platformName);
485}
486export interface PlatformConfig {
487 isEngine?: boolean;
488 initialize?: Function;
489 isMatch?: Function;
490 superset?: string;
491 subsets?: string[];
492 settings?: any;
493 versionParser?: any;
494}
495export interface PlatformVersion {
496 str?: string;
497 num?: number;
498 major?: number;
499 minor?: number;
500}
501export interface EventListenerOptions {
502 capture?: boolean;
503 passive?: boolean;
504 zone?: boolean;
505}
506/**
507 * @hidden
508 */
509export declare function setupPlatform(doc: HTMLDocument, platformConfigs: {
510 [key: string]: PlatformConfig;
511}, zone: NgZone): Platform;