Skip to content

Instantly share code, notes, and snippets.

@G33N
Created October 5, 2021 19:38
Show Gist options
  • Save G33N/9d8b18031cc17c8129ee50a952c04a96 to your computer and use it in GitHub Desktop.
Save G33N/9d8b18031cc17c8129ee50a952c04a96 to your computer and use it in GitHub Desktop.
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