forked from GertjanReynaert/react-native-device
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.js
More file actions
55 lines (43 loc) · 1.16 KB
/
Copy pathDevice.js
File metadata and controls
55 lines (43 loc) · 1.16 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
var Dimensions = require('Dimensions');
class Device {
constructor() {
this.width = this._width();
this.height = this._height();
this.kind = this._kind();
}
isIpad() {
return this.kind.indexOf("iPad") === 0;
}
isIphone() {
return this.kind.indexOf("iPhone") === 0;
}
_kind() {
var iPad = [768, 1024];
var iPhone4 = [320, 480];
var iPhone5 = [320, 568];
var iPhone6 = [375, 667];
var iPhone6plus = [414, 736];
if (iPad.indexOf(this.width) > -1 && iPad.indexOf(this.height) > -1) {
return "iPad";
}
if (iPhone4.indexOf(this.width) > -1 && iPhone4.indexOf(this.height) > -1) {
return "iPhone4";
}
if (iPhone5.indexOf(this.width) > -1 && iPhone5.indexOf(this.height) > -1) {
return "iPhone5";
}
if (iPhone6.indexOf(this.width) > -1 && iPhone6.indexOf(this.height) > -1) {
return "iPhone6";
}
if (iPhone6plus.indexOf(this.width) > -1 && iPhone6plus.indexOf(this.height) > -1) {
return "iPhone6plus";
}
}
_width() {
return Dimensions.get("window").width;
}
_height() {
return Dimensions.get("window").height;
}
}
module.exports = new Device();