device

Extends NativeObject

Provides information about the device that executes the application.

Import this object with “const {device} = require('tabris');

Example:

let lang = device.language;

device.on("orientationChanged", ({value: orientation}) => console.log("new orientation: ", orientation));

Properties

language

read-only
Type: string

The user language configured on the device as an RFC 4646 compliant string. For example "de", "es-ES", etc. This property is also available globally as navigator.language.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

model

read-only
Type: string

The name of the device model. For example "iPad4,1" or "Nexus 7". This property is also available globally as device.model.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

orientation

read-only
Type: string, supported values: portrait-primary, portrait-secondary, landscape-primary, landscape-secondary

The device orientation. One of portrait-primary, portrait-secondary, landscape-primary, and landscape-secondary.

platform

Type: string, supported values: Android, iOS, windows

The name of the platform. Currently either "Android", "iOS", or "windows". This property is also available globally as device.platform.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

scaleFactor

read-only
Type: number

The ratio between physical pixels and device independent pixels. This property is also available globally as window.devicePixelRatio.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

screenHeight

read-only
Type: number

The entire height of the device’s screen in device independent pixel. Depends on the current device orientation. This property is also available globally as screen.height.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

screenWidth

read-only
Type: number

The entire width of the device’s screen in device independent pixel. Depends on the current device orientation. This property is also available as globally as screen.width.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

vendor

read-only
Type: string

The name of the device manufacture. For example "Samsung" or "Apple". This property is also available globally as device.vendor.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

version

read-only
Type: string

The platform version. On iOS it looks like this: "8.1.1". On Android, the version code is returned. This property is also available globally as device.version.
This property can only be set on widget creation. Once set, it cannot be changed anymore.

win_keyboardPresent

Windows 10

read-only
Type: boolean

Returns true if a hardware keyboard is present. The developer may choose to handle some user input differently in that case. Available only on windows.

win_primaryInput

Windows 10

read-only
Type: boolean, supported values: touch, mouse

On a PC this returns "touch" when in tablet mode, otherwise "mouse". On phones this this returns "mouse" when displayed on an external display (“Continuum”), otherwise "touch". Available only on windows

Events

orientationChanged

Fired when the orientation property has changed and the rotation animation has finished.

Event Parameters

  • target: this The widget the event was fired on.

  • value: string The new value of orientation.

win_keyboardPresentChanged

Fired when the win_keyboardPresent property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: boolean The new value of win_keyboardPresent.

win_primaryInputChanged

Fired when the win_primaryInput property has changed.

Event Parameters

  • target: this The widget the event was fired on.

  • value: boolean The new value of win_primaryInput.

Example

const {TextView, device, ui} = require('tabris');

// Display available device information

['platform', 'version', 'model', 'vendor', 'language', 'orientation'].forEach((property) => {
  new TextView({
    id: property,
    left: 10, right: 10, top: 'prev() 10',
    text: property + ': ' + device[property]
  }).appendTo(ui.contentView);
});

device.on('orientationChanged', ({value: orientation}) => {
  ui.contentView.find('#orientation').set('text', 'orientation: ' + orientation);
});