forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.ios.ts
More file actions
80 lines (67 loc) · 2.29 KB
/
platform.ios.ts
File metadata and controls
80 lines (67 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* tslint:disable:class-name */
import definition = require("platform");
import enums = require("ui/enums");
export module platformNames {
export var android = "Android";
export var ios = "iOS";
}
// This is a "static" class and it is used like a name-space.
// It is not meant to be initialized - thus it is not capitalized
export class device implements definition.device {
private static _model: string;
private static _osVersion: string;
private static _sdkVersion: string;
private static _deviceType: string;
static get os(): string {
return platformNames.ios;
}
static get osVersion(): string {
if (!device._osVersion) {
device._osVersion = UIDevice.currentDevice().systemVersion;
}
return device._osVersion;
}
static get model(): string {
if (!device._model) {
device._model = UIDevice.currentDevice().model;
}
return device._model;
}
static get sdkVersion(): string {
if (!device._sdkVersion) {
device._sdkVersion = UIDevice.currentDevice().systemVersion;
}
return device._sdkVersion;
}
static get deviceType(): string {
if (!device._deviceType) {
if (UIDevice.currentDevice().userInterfaceIdiom === UIUserInterfaceIdiom.UIUserInterfaceIdiomPhone) {
device._deviceType = enums.DeviceType.Phone;
}
else {
device._deviceType = enums.DeviceType.Tablet;
}
}
return device._deviceType;
}
}
var mainScreenInfo: definition.ScreenMetrics = null;
// This is a "static" class and it is used like a name-space.
// It is not meant to be initialized - thus it is not capitalized
export class screen implements definition.screen {
static get mainScreen(): definition.ScreenMetrics {
if (!mainScreenInfo) {
var mainScreen = UIScreen.mainScreen();
if (mainScreen) {
var size = mainScreen.bounds.size;
var scale = mainScreen.scale;
mainScreenInfo = {
widthPixels: size.width * scale,
heightPixels: size.height * scale,
scale: scale
}
}
}
return mainScreenInfo;
}
}