-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (51 loc) · 1.13 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
/*
* @Author: Oboo Chin
* @Date: 2017-12-16 14:20:59
* @Last Modified by: Oboo Chin
* @Last Modified time: 2017-12-16 14:21:32
*/
import { StyleSheet, Dimensions } from "react-native";
const currentDeviceWidth = Dimensions.get("window").width;
const iPhoneSEWidth = 320;
// properties will be zoom
const scaleProps = [
"width",
"height",
"maxHeight",
"minHeight",
"margin",
"marginLeft",
"marginRight",
"marginTop",
"marginBottom",
"padding",
"paddingLeft",
"paddingRight",
"paddingTop",
"paddingBottom",
"top",
"left",
"right",
"bottom",
"fontSize",
"borderRadius",
];
const scale = currentDeviceWidth / iPhoneSEWidth;
const StyleTransformer = {};
const styleTransformer = styleObj => {
Object.keys(styleObj).forEach(key => {
if (scaleProps.includes(key)) {
styleObj[key] *= scale;
}
});
return styleObj;
};
StyleTransformer.create = (styles = {}) => {
Object.keys(styles).forEach(key => {
styles[key] = styleTransformer(styles[key]);
});
return StyleSheet.create(styles);
};
// export default StyleSheet;
export default StyleTransformer;
export const ts = v => v * scale;