forked from heyman333/react-native-responsive-fontSize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 1.23 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
import { isIphoneX } from "react-native-iphone-x-helper";
import { Platform, StatusBar, Dimensions } from "react-native";
export function RFPercentage(percent) {
const { height, width } = Dimensions.get("window");
const standardLength = width > height ? width : height;
const offset =
width > height ? 0 : Platform.OS === "ios" ? 78 : StatusBar.currentHeight; // iPhone X style SafeAreaView size in portrait
const deviceHeight =
isIphoneX() || Platform.OS === "android"
? standardLength - offset
: standardLength;
const heightPercent = (percent * deviceHeight) / 100;
return Math.round(heightPercent);
}
// guideline height for standard 5" device screen is 680
export function RFValue(fontSize, standardScreenHeight = 680) {
const { height, width } = Dimensions.get("window");
const standardLength = width > height ? width : height;
const offset =
width > height ? 0 : Platform.OS === "ios" ? 78 : StatusBar.currentHeight; // iPhone X style SafeAreaView size in portrait
const deviceHeight =
isIphoneX() || Platform.OS === "android"
? standardLength - offset
: standardLength;
const heightPercent = (fontSize * deviceHeight) / standardScreenHeight;
return Math.round(heightPercent);
}