-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
61 lines (53 loc) · 1.49 KB
/
index.js
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
import React, {
PixelRatio,
Platform,
Dimensions
} from 'react-native';
const windowSize = Dimensions.get('window');
class DetectDeviceService {
constructor() {
this.pixelDensity = PixelRatio.get();
this.width = windowSize.width;
this.height = windowSize.height;
this.adjustedWidth = this.width * this.pixelDensity;
this.adjustedHeight = this.height * this.pixelDensity;
this.isPhoneOrTablet();
this.isIosOrAndroid();
this.detectIphoneX();
}
isPhoneOrTablet() {
if (this.pixelDensity < 2 && (this.adjustedWidth >= 1000 || this.adjustedHeight >= 1000)) {
this.isTablet = true;
this.isPhone = false;
} else if (this.pixelDensity === 2 && (this.adjustedWidth >= 1824 || this.adjustedHeight >= 1824)) {
this.isTablet = true;
this.isPhone = false;
} else {
this.isTablet = false;
this.isPhone = true;
}
}
isIosOrAndroid() {
if (Platform.OS === 'ios') {
this.isIos = true;
this.isAndroid = false;
} else {
this.isIos = false;
this.isAndroid = true;
}
}
detectIphoneX() {
if (Platform.OS === 'ios' &&
!Platform.isPad &&
!Platform.isTVOS &&
(
(windowSize.height === 812 || windowSize.width === 812) || // iPhone X and iPhone XS
(windowSize.height === 896 || windowSize.width === 896) // iPhone XS Max and XR
)) {
this.isIphoneX = true;
} else {
this.isIphoneX = false;
}
}
}
module.exports = new DetectDeviceService();