-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize.ts
47 lines (40 loc) · 1.1 KB
/
normalize.ts
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
import {PixelRatio, StyleSheet} from 'react-native';
import {Dimensions} from 'react-native';
const {
width: SCREEN_WIDTH,
height: SCREEN_HEIGHT
} = Dimensions.get('window');
const widthBaseScale = SCREEN_WIDTH / 414;
const heightBaseScale = SCREEN_HEIGHT / 896;
function normalize(size: number, based = 'width') {
const newSize = (based === 'height') ?
size * heightBaseScale : size * widthBaseScale;
return Math.round(PixelRatio.roundToNearestPixel(newSize));
}
//for width pixel
const widthPixel = (size: number) => {
return normalize(size, 'width');
};
//for height pixel
const heightPixel = (size: number) => {
return normalize(size, 'height');
};
//for font pixel
const fontPixel = (size: number) => {
return heightPixel(size);
};
//for Margin and Padding vertical pixel
const pixelSizeVertical = (size: number) => {
return heightPixel(size);
};
//for Margin and Padding horizontal pixel
const pixelSizeHorizontal = (size: number) => {
return widthPixel(size);
};
export {
widthPixel,
heightPixel,
fontPixel,
pixelSizeVertical,
pixelSizeHorizontal
};