Options
All
  • Public
  • Public/Protected
  • All
Menu
class

Platform

description

The Platform service can be used to get information about your current device. You can get all of the platforms associated with the device using the platforms method, including whether the app is being viewed from a mobile/tablet/desktop, if it's on a mobile device or browser, and the exact System (iOS, Android, Windows etc). You can also get the orientation of the device, if it uses right-to-left language direction, and much much more. With this information you can completely customize your app to fit any device.

example
import { Platform } from 'tp-platform';

const plt = new Platform({});

Hierarchy

  • Platform

Index

Constructors

constructor

Properties

Css

Css: object
internal

Type declaration

  • Optional animationDelay?: undefined | string
  • Optional transform?: undefined | string
  • Optional transformOrigin?: undefined | string
  • Optional transition?: undefined | string
  • Optional transitionDelay?: undefined | string
  • Optional transitionDuration?: undefined | string
  • Optional transitionEnd?: undefined | string
  • Optional transitionStart?: undefined | string
  • Optional transitionTimingFn?: undefined | string

Private _core

_core: string = ""

Private _dir

Private _doc

_doc: HTMLDocument

Private _isPortrait

_isPortrait: boolean | null = null

Private _lH

_lH: number = 0

Private _lW

_lW: number = 0

Private _lang

_lang: string = ""

Private _nPlt

_nPlt: string = ""

Private _pH

_pH: number = 0

Private _pW

_pW: number = 0

_platforms

_platforms: string[] = []
internal

Private _qp

_qp: QueryParams = new QueryParams()

Private _readyPromise

_readyPromise: Promise<any>

Private _readyReject

_readyReject: any

Private _readyResolve

_readyResolve: any

Private _registry

_registry: object

Type declaration

_settings

_settings: any

Private _ua

_ua: string = ""

Private _uiEvtOpts

_uiEvtOpts: any = (registerListener as any)._uiEvtOpts

Private _versions

_versions: object

Type declaration

Private _win

_win: Window

isRTL

isRTL: boolean

Returns if this app is using right-to-left language direction or not. We recommend the app's index.html file already has the correct dir attribute value set, such as <html dir="ltr"> or <html dir="rtl">. W3C: Structural markup and right-to-left text in HTML

returns

Methods

Private _calcDim

  • _calcDim(): void

Private _initEvents

  • _initEvents(): void

dir

Private getQueryData

  • getQueryData(): any
  • 获取带有私有前缀的url参数对象

    Returns any

getQueryParam

  • getQueryParam(key: string): any
  • Get the query string parameter

    Parameters

    • key: string

    Returns any

height

  • height(): number
  • Gets the height of the platform's viewport using window.innerHeight. Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads.

    Returns number

is

  • is(platformName: string): boolean
  • description

    Depending on the platform the user is on, is(platformName) will return true or false. Note that the same app can return true for more than one platform name. For example, an app running from an iPad would return true for the platform names: mobile, ios, ipad, and tablet. Additionally, if the app was running from Cordova then cordova would be true, and if it was running from a web browser on the iPad then web would be true.

    import { setupPlatform } from 'tp-platform';
    
    const plt = setupPlatform({});
    plt.is('ios');  // true or false
    
    Type Type Name Platform Name Description
    0 Base core base application.
    1 Platform mobile on a mobile platform.
    1 Platform tablet on a tablet platform.
    1 Platform desktop on a desktop platform.
    2 System android on a device running Android System.
    2 System ios on a device running iOS System.
    2 System linux on a device running Linux System.
    2 System windows on a device running Windows System.
    2 System mac on a device running Mac OS.
    3 Brand ipad on an iPad device.
    3 Brand iphone on an iPhone device.
    4 Environment cordova on a hybrid environment(cordova).
    4 Environment electron on a hybrid environment(electron).
    4 Environment web on an ordinary web browser.

    Parameters

    • platformName: string

    Returns boolean

    returns true/false based on platform.

isLandscape

  • isLandscape(): boolean
  • Returns true if the app is in landscape mode.

    Returns boolean

isPortrait

  • isPortrait(): boolean
  • Returns true if the app is in portait mode.

    Returns boolean

lang

  • lang(): string
  • Returns app's language and optional country code. We recommend the app's index.html file already has the correct lang attribute value set, such as <html lang="en">. W3C: Declaring language in HTML

    Returns string

platforms

  • platforms(): Array<string>
  • description

    Depending on what device you are on, platforms can return multiple values. Each possible value is a type of platforms. For example, on an iPhone, it would return core, mobile, ios, and iphone.

    import { setupPlatform } from 'tp-platform';
    
    const plt = setupPlatform({});
    plt.platforms();  // ['core', 'mobile', 'ios', 'iphone'].
    

    Returns Array<string>

    the array of platforms

ready

  • ready(): Promise<string>
  • Returns a promise when the platform is ready and native functionality can be called. If the app is running from within a web browser, then the promise will resolve when the DOM is ready. When the app is running from an hybrid application such as Cordova/Electron/Weichat/Alipay, then the promise will resolve when hybrid application execute the triggerReady function.

    The resolved value is the readySource, which states which platform ready was used. For example, when Cordova is ready, the resolved ready source is cordova. The default ready source value will be dom. The readySource is useful if different logic should run depending on the platform the app is running from. For example, only Cordova can execute the status bar plugin, so the web should not run status bar plugin logic.

    import { setupPlatform } from 'tp-platform';
    
    const plt = setupPlatform({});
    plt.ready().then(function (readySource) {
       switch (readySource) {
         case 'dom':
           console.log('web env');
           break;
         case 'cordova':
           console.log('cordova env');
           break;
         case 'electron':
           console.log('electron env');
           break;
         case 'alipay':
           console.log('alipay env');
           break;
         case 'dingtalk':
           console.log('dingtalk env');
           break;
         case 'wechat':
           console.log('wechat env');
           break;
         default:
           console.log(readySource + ' not found!');
       }
    }, function (reason) {
      console.error('ready error', reason)
    });
    

    Returns Promise<string>

setDir

  • Set the app's language direction, which will update the dir attribute on the app's root <html> element. We recommend the app's index.html file already has the correct dir attribute value set, such as <html dir="ltr"> or <html dir="rtl">. This method is useful if the direction needs to be dynamically changed per user/session. W3C: Structural markup and right-to-left text in HTML

    Parameters

    Returns void

setLang

  • setLang(language: string, updateDocument: boolean): void
  • Set the app's language and optionally the country code, which will update the lang attribute on the app's root <html> element. We recommend the app's index.html file already has the correct lang attribute value set, such as <html lang="en">. This method is useful if the language needs to be dynamically changed per user/session. W3C: Declaring language in HTML

    Parameters

    • language: string

      Examples: en-US, en-GB, ar, de, zh, es-MX

    • updateDocument: boolean

      Specifies whether the lang attribute of <html> should be updated

    Returns void

settings

  • settings(): any
  • Get the final configuration for the matching platform.

    Returns any

testUserAgent

  • testUserAgent(expression: string): boolean

triggerFail

  • triggerFail(reason: string): void

url

  • url(): string

versions

  • versions(): object
  • Returns an object containing version information about all of the platforms.

    import { setupPlatform } from 'tp-platform';
    
    const plt = setupPlatform({});
    plt.versions();  // {ios: {str: "10.3.0", num: 10.3, major: 10, minor: 3, patch: 0}}.
    

    Returns object

    An object containing all of the platforms and their versions.

width

  • width(): number
  • Gets the width of the platform's viewport using window.innerWidth. Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads.

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc