UNPKG

@nativescript/core

Version:

A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.

102 lines 3.08 kB
/* tslint:disable:class-name */ import { platformNames } from './common'; import { ios } from '../utils'; export * from './common'; class DeviceRef { get manufacturer() { return 'Apple'; } get os() { if (__VISIONOS__) { return platformNames.visionos; } else { return platformNames.ios; } } get osVersion() { if (!this._osVersion) { this._osVersion = UIDevice.currentDevice.systemVersion; } return this._osVersion; } get model() { if (!this._model) { this._model = UIDevice.currentDevice.model; } return this._model; } get sdkVersion() { if (!this._sdkVersion) { this._sdkVersion = UIDevice.currentDevice.systemVersion; } return this._sdkVersion; } get deviceType() { if (!this._deviceType) { if (UIDevice.currentDevice.userInterfaceIdiom === 0 /* UIUserInterfaceIdiom.Phone */) { this._deviceType = 'Phone'; } else if (UIDevice.currentDevice.userInterfaceIdiom === 6 /* UIUserInterfaceIdiom.Vision */) { this._deviceType = 'Tablet'; // TODO: could add conditions throughout core for this // this._deviceType = 'Vision'; } else { this._deviceType = 'Tablet'; } } return this._deviceType; } get uuid() { const userDefaults = NSUserDefaults.standardUserDefaults; const uuid_key = 'TNSUUID'; let app_uuid = userDefaults.stringForKey(uuid_key); if (!app_uuid) { app_uuid = NSUUID.UUID().UUIDString; userDefaults.setObjectForKey(app_uuid, uuid_key); userDefaults.synchronize(); } return app_uuid; } get language() { return NSLocale.preferredLanguages[0]; } get region() { return NSLocale.currentLocale.objectForKey(NSLocaleCountryCode); } } class MainScreen { get screen() { if (!this._screen) { // NOTE: may not want to cache this value with SwiftUI app lifecycle based apps (using NativeScriptViewFactory) given the potential of multiple scenes const window = ios.getWindow(); this._screen = window ? window.screen : UIScreen.mainScreen; } return this._screen; } get widthPixels() { return this.widthDIPs * this.scale; } get heightPixels() { return this.heightDIPs * this.scale; } get scale() { return this.screen.scale; } get widthDIPs() { return this.screen.bounds.size.width; } get heightDIPs() { return this.screen.bounds.size.height; } } export const Device = new DeviceRef(); // This retains compatibility with NS6 export const device = Device; export class Screen { } Screen.mainScreen = new MainScreen(); // This retains compatibility with NS6 export const screen = Screen; //# sourceMappingURL=index.ios.js.map