-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
113 lines (113 loc) · 2.44 KB
/
index.js
File metadata and controls
113 lines (113 loc) · 2.44 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { Dimensions } from 'react-native'
const { height, width } = Dimensions.get('window')
const CURRENT_RESOLUTION = Math.sqrt(height * height + width * width)
export const PREDEF_RES = {
iphoneX: {
px: {
width: 1125,
height: 2436
},
dp: {
width: 375,
height: 812
}
},
iphone8P: {
px: {
width: 1080,
height: 1920
},
dp: {
width: 414,
height: 736
}
},
iphone8: {
px: {
width: 750,
height: 1334
},
dp: {
width: 375,
height: 667
}
},
iphone7P: {
px: {
width: 1080,
height: 1920
},
dp: {
width: 414,
height: 736
}
},
iphone6sP: {
px: {
width: 1080,
height: 1920
},
dp: {
width: 375,
height: 667
}
},
iphone6P: {
px: {
width: 1080,
height: 1920
},
dp: {
width: 375,
height: 667
}
},
iphone7: {
px: {
width: 750,
height: 1334
},
dp: {
width: 375,
height: 667
}
},
iphone6s: {
px: {
width: 750,
height: 1334
},
dp: {
width: 375,
height: 667
}
},
iphone6: {
px: {
width: 750,
height: 1334
},
dp: {
width: 375,
height: 667
}
},
iphoneSE: {
px: {
width: 640,
height: 1136
},
dp: {
width: 320,
height: 568
}
}
}
export const create = (designSize = { width: 414, height: 736 }) => {
if (!designSize || !designSize.width || !designSize.height || typeof designSize.width !== 'number' || typeof designSize.height !== 'number') {
throw new Error('react-native-pixel-perfect | create function | Invalid design size object! must have width and height fields of type Number.')
}
const DESIGN_RESOLUTION = Math.sqrt(designSize.height * designSize.height + designSize.width * designSize.width)
const RESOLUTIONS_PROPORTION = CURRENT_RESOLUTION / DESIGN_RESOLUTION
return size => RESOLUTIONS_PROPORTION * size
}