123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. import { EventEmitter, NgZone } from '@angular/core';
  2. export 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. */
  27. export 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. *
  127. * @param {string} platformName
  128. */
  129. is(platformName: string): boolean;
  130. /**
  131. * @returns {array} the array of platforms
  132. * @description
  133. * Depending on what device you are on, `platforms` can return multiple values.
  134. * Each possible value is a hierarchy of platforms. For example, on an iPhone,
  135. * it would return `mobile`, `ios`, and `iphone`.
  136. *
  137. * ```
  138. * import { Platform } from 'ionic-angular';
  139. *
  140. * @Component({...})
  141. * export MyPage {
  142. * constructor(public platform: Platform) {
  143. * // This will print an array of the current platforms
  144. * console.log(this.platform.platforms());
  145. * }
  146. * }
  147. * ```
  148. */
  149. platforms(): Array<string>;
  150. /**
  151. * Returns an object containing version information about all of the platforms.
  152. *
  153. * ```
  154. * import { Platform } from 'ionic-angular';
  155. *
  156. * @Component({...})
  157. * export MyPage {
  158. * constructor(public platform: Platform) {
  159. * // This will print an object containing
  160. * // all of the platforms and their versions
  161. * console.log(platform.versions());
  162. * }
  163. * }
  164. * ```
  165. *
  166. * @returns {object} An object containing all of the platforms and their versions.
  167. */
  168. versions(): {
  169. [name: string]: PlatformVersion;
  170. };
  171. /**
  172. * @hidden
  173. */
  174. version(): PlatformVersion;
  175. /**
  176. * Returns a promise when the platform is ready and native functionality
  177. * can be called. If the app is running from within a web browser, then
  178. * the promise will resolve when the DOM is ready. When the app is running
  179. * from an application engine such as Cordova, then the promise will
  180. * resolve when Cordova triggers the `deviceready` event.
  181. *
  182. * The resolved value is the `readySource`, which states which platform
  183. * ready was used. For example, when Cordova is ready, the resolved ready
  184. * source is `cordova`. The default ready source value will be `dom`. The
  185. * `readySource` is useful if different logic should run depending on the
  186. * platform the app is running from. For example, only Cordova can execute
  187. * the status bar plugin, so the web should not run status bar plugin logic.
  188. *
  189. * ```
  190. * import { Component } from '@angular/core';
  191. * import { Platform } from 'ionic-angular';
  192. *
  193. * @Component({...})
  194. * export MyApp {
  195. * constructor(public platform: Platform) {
  196. * this.platform.ready().then((readySource) => {
  197. * console.log('Platform ready from', readySource);
  198. * // Platform now ready, execute any required native code
  199. * });
  200. * }
  201. * }
  202. * ```
  203. * @returns {promise}
  204. */
  205. ready(): Promise<string>;
  206. /**
  207. * @hidden
  208. * This should be triggered by the engine when the platform is
  209. * ready. If there was no custom prepareReady method from the engine,
  210. * such as Cordova or Electron, then it uses the default DOM ready.
  211. */
  212. triggerReady(readySource: string): void;
  213. /**
  214. * @hidden
  215. * This is the default prepareReady if it's not replaced by an engine,
  216. * such as Cordova or Electron. If there was no custom prepareReady
  217. * method from an engine then it uses the method below, which triggers
  218. * the platform ready on the DOM ready event, and the default resolved
  219. * value is `dom`.
  220. */
  221. prepareReady(): void;
  222. /**
  223. * Set the app's language direction, which will update the `dir` attribute
  224. * on the app's root `<html>` element. We recommend the app's `index.html`
  225. * file already has the correct `dir` attribute value set, such as
  226. * `<html dir="ltr">` or `<html dir="rtl">`. This method is useful if the
  227. * direction needs to be dynamically changed per user/session.
  228. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
  229. * @param {DocumentDirection} dir Examples: `rtl`, `ltr`
  230. * @param {boolean} updateDocument
  231. */
  232. setDir(dir: DocumentDirection, updateDocument: boolean): void;
  233. /**
  234. * Returns app's language direction.
  235. * We recommend the app's `index.html` file already has the correct `dir`
  236. * attribute value set, such as `<html dir="ltr">` or `<html dir="rtl">`.
  237. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
  238. * @returns {DocumentDirection}
  239. */
  240. dir(): DocumentDirection;
  241. /**
  242. * Returns if this app is using right-to-left language direction or not.
  243. * We recommend the app's `index.html` file already has the correct `dir`
  244. * attribute value set, such as `<html dir="ltr">` or `<html dir="rtl">`.
  245. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
  246. * @returns {boolean}
  247. */
  248. isRTL: boolean;
  249. /**
  250. * Set the app's language and optionally the country code, which will update
  251. * the `lang` attribute on the app's root `<html>` element.
  252. * We recommend the app's `index.html` file already has the correct `lang`
  253. * attribute value set, such as `<html lang="en">`. This method is useful if
  254. * the language needs to be dynamically changed per user/session.
  255. * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations)
  256. * @param {string} language Examples: `en-US`, `en-GB`, `ar`, `de`, `zh`, `es-MX`
  257. * @param {boolean} updateDocument Specifies whether the `lang` attribute of `<html>` should be updated
  258. */
  259. setLang(language: string, updateDocument: boolean): void;
  260. /**
  261. * Returns app's language and optional country code.
  262. * We recommend the app's `index.html` file already has the correct `lang`
  263. * attribute value set, such as `<html lang="en">`.
  264. * [W3C: Declaring language in HTML](http://www.w3.org/International/questions/qa-html-language-declarations)
  265. * @returns {string}
  266. */
  267. lang(): string;
  268. /**
  269. * @hidden
  270. */
  271. exitApp(): void;
  272. /**
  273. * @hidden
  274. */
  275. backButton: EventEmitter<Event>;
  276. /**
  277. * The pause event emits when the native platform puts the application
  278. * into the background, typically when the user switches to a different
  279. * application. This event would emit when a Cordova app is put into
  280. * the background, however, it would not fire on a standard web browser.
  281. */
  282. pause: EventEmitter<Event>;
  283. /**
  284. * The resume event emits when the native platform pulls the application
  285. * out from the background. This event would emit when a Cordova app comes
  286. * out from the background, however, it would not fire on a standard web browser.
  287. */
  288. resume: EventEmitter<Event>;
  289. /**
  290. * The resize event emits when the browser window has changed dimensions. This
  291. * could be from a browser window being physically resized, or from a device
  292. * changing orientation.
  293. */
  294. resize: EventEmitter<Event>;
  295. /**
  296. * The back button event is triggered when the user presses the native
  297. * platform's back button, also referred to as the "hardware" back button.
  298. * This event is only used within Cordova apps running on Android and
  299. * Windows platforms. This event is not fired on iOS since iOS doesn't come
  300. * with a hardware back button in the same sense an Android or Windows device
  301. * does.
  302. *
  303. * Registering a hardware back button action and setting a priority allows
  304. * apps to control which action should be called when the hardware back
  305. * button is pressed. This method decides which of the registered back button
  306. * actions has the highest priority and should be called.
  307. *
  308. * @param {Function} fn Called when the back button is pressed,
  309. * if this registered action has the highest priority.
  310. * @param {number} priority Set the priority for this action. Only the highest priority will execute. Defaults to `0`.
  311. * @returns {Function} A function that, when called, will unregister
  312. * the back button action.
  313. */
  314. registerBackButtonAction(fn: Function, priority?: number): Function;
  315. /**
  316. * @hidden
  317. */
  318. runBackButtonAction(): void;
  319. /**
  320. * @hidden
  321. */
  322. setUserAgent(userAgent: string): void;
  323. /**
  324. * @hidden
  325. */
  326. setQueryParams(url: string): void;
  327. /**
  328. * Get the query string parameter
  329. */
  330. getQueryParam(key: string): any;
  331. /**
  332. * Get the current url.
  333. */
  334. url(): string;
  335. /**
  336. * @hidden
  337. */
  338. userAgent(): string;
  339. /**
  340. * @hidden
  341. */
  342. setNavigatorPlatform(navigatorPlt: string): void;
  343. /**
  344. * @hidden
  345. */
  346. navigatorPlatform(): string;
  347. /**
  348. * Gets the width of the platform's viewport using `window.innerWidth`.
  349. * Using this method is preferred since the dimension is a cached value,
  350. * which reduces the chance of multiple and expensive DOM reads.
  351. */
  352. width(): number;
  353. /**
  354. * Gets the height of the platform's viewport using `window.innerHeight`.
  355. * Using this method is preferred since the dimension is a cached value,
  356. * which reduces the chance of multiple and expensive DOM reads.
  357. */
  358. height(): number;
  359. /**
  360. * @hidden
  361. */
  362. getElementComputedStyle(ele: HTMLElement, pseudoEle?: string): CSSStyleDeclaration;
  363. /**
  364. * @hidden
  365. */
  366. getElementFromPoint(x: number, y: number): HTMLElement;
  367. /**
  368. * @hidden
  369. */
  370. getElementBoundingClientRect(ele: HTMLElement): ClientRect;
  371. /**
  372. * Returns `true` if the app is in portait mode.
  373. */
  374. isPortrait(): boolean;
  375. /**
  376. * Returns `true` if the app is in landscape mode.
  377. */
  378. isLandscape(): boolean;
  379. private _calcDim();
  380. /**
  381. * @hidden
  382. * This requestAnimationFrame will NOT be wrapped by zone.
  383. */
  384. raf(callback: {
  385. (timeStamp?: number): void;
  386. } | Function): number;
  387. /**
  388. * @hidden
  389. */
  390. cancelRaf(rafId: number): any;
  391. /**
  392. * @hidden
  393. * This setTimeout will NOT be wrapped by zone.
  394. */
  395. timeout(callback: Function, timeout?: number): number;
  396. /**
  397. * @hidden
  398. * This setTimeout will NOT be wrapped by zone.
  399. */
  400. cancelTimeout(timeoutId: number): void;
  401. /**
  402. * @hidden
  403. * Built to use modern event listener options, like "passive".
  404. * If options are not supported, then just return a boolean which
  405. * represents "capture". Returns a method to remove the listener.
  406. */
  407. registerListener(ele: any, eventName: string, callback: {
  408. (ev?: UIEvent): void;
  409. }, opts: EventListenerOptions, unregisterListenersCollection?: Function[]): Function;
  410. /**
  411. * @hidden
  412. */
  413. transitionEnd(el: HTMLElement, callback: {
  414. (ev?: TransitionEvent): void;
  415. }, zone?: boolean): () => void;
  416. /**
  417. * @hidden
  418. */
  419. windowLoad(callback: Function): void;
  420. /**
  421. * @hidden
  422. */
  423. isActiveElement(ele: HTMLElement): boolean;
  424. /**
  425. * @hidden
  426. */
  427. getActiveElement(): Element;
  428. /**
  429. * @hidden
  430. */
  431. hasFocus(ele: HTMLElement): boolean;
  432. /**
  433. * @hidden
  434. */
  435. hasFocusedTextInput(): boolean;
  436. /**
  437. * @hidden
  438. */
  439. focusOutActiveElement(): void;
  440. private _initEvents();
  441. /**
  442. * @hidden
  443. */
  444. setPlatformConfigs(platformConfigs: {
  445. [key: string]: PlatformConfig;
  446. }): void;
  447. /**
  448. * @hidden
  449. */
  450. getPlatformConfig(platformName: string): PlatformConfig;
  451. /**
  452. * @hidden
  453. */
  454. registry(): {
  455. [name: string]: PlatformConfig;
  456. };
  457. /**
  458. * @hidden
  459. */
  460. setDefault(platformName: string): void;
  461. /**
  462. * @hidden
  463. */
  464. testQuery(queryValue: string, queryTestValue: string): boolean;
  465. /**
  466. * @hidden
  467. */
  468. testNavigatorPlatform(navigatorPlatformExpression: string): boolean;
  469. /**
  470. * @hidden
  471. */
  472. matchUserAgentVersion(userAgentExpression: RegExp): any;
  473. testUserAgent(expression: string): boolean;
  474. /**
  475. * @hidden
  476. */
  477. isPlatformMatch(queryStringName: string, userAgentAtLeastHas?: string[], userAgentMustNotHave?: string[]): boolean;
  478. /** @hidden */
  479. init(): void;
  480. /**
  481. * @hidden
  482. */
  483. private matchPlatform(platformName);
  484. }
  485. export interface PlatformConfig {
  486. isEngine?: boolean;
  487. initialize?: Function;
  488. isMatch?: Function;
  489. superset?: string;
  490. subsets?: string[];
  491. settings?: any;
  492. versionParser?: any;
  493. }
  494. export interface PlatformVersion {
  495. str?: string;
  496. num?: number;
  497. major?: number;
  498. minor?: number;
  499. }
  500. export interface EventListenerOptions {
  501. capture?: boolean;
  502. passive?: boolean;
  503. zone?: boolean;
  504. }
  505. /**
  506. * @hidden
  507. */
  508. export declare function setupPlatform(doc: HTMLDocument, platformConfigs: {
  509. [key: string]: PlatformConfig;
  510. }, zone: NgZone): Platform;