-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 1.03 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
import { PixelRatio, Dimensions } from 'react-native';
const gcd = (a, b) => {
if (b === 0) {
return a;
}
return gcd(b, a % b);
};
const isTablet = () => {
const pixelDensity = PixelRatio.get();
const width = Dimensions.get("window").width;
const height = Dimensions.get("window").height;
const adjustedWidth = width * pixelDensity;
const adjustedHeight = height * pixelDensity;
const swidth = Dimensions.get("screen").width;
const sheight = Dimensions.get("screen").height;
const sadjustedWidth = swidth * pixelDensity;
const sadjustedHeight = sheight * pixelDensity;
const ratioDivider = gcd(sadjustedWidth, sadjustedHeight);
const wRatio = sadjustedWidth / ratioDivider;
const hRatio = sadjustedHeight / ratioDivider;
if (wRatio === 9 && hRatio === 20) {
return false;
}
if (pixelDensity < 2 && (adjustedWidth >= 1000 || adjustedHeight >= 1000)) {
return true;
} else
return (
pixelDensity === 2 && (adjustedWidth >= 1920 || adjustedHeight >= 1920)
);
}
export default isTablet;