Created
October 5, 2021 19:38
-
-
Save G33N/9d8b18031cc17c8129ee50a952c04a96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {isIphoneX} from 'react-native-iphone-x-helper'; | |
import {Platform, StatusBar, Dimensions} from 'react-native'; | |
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; | |
export function RFPercentage(percent: number) { | |
const heightPercent = (percent * deviceHeight) / 100; | |
return Math.round(heightPercent); | |
} | |
// guideline height for standard 5" device screen is 680 | |
export function RFValue(fontSize: number, standardScreenHeight = 680) { | |
const heightPercent = (fontSize * deviceHeight) / standardScreenHeight; | |
return Math.round(heightPercent); | |
} | |
export function RFPercentageWidth(percent: number) { | |
const widthPercent = (percent * width) / 100; | |
return Math.round(widthPercent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment