Skip to content

Instantly share code, notes, and snippets.

@shreyakupadhyay
Created April 25, 2020 23:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shreyakupadhyay/2b0c6a898c7e59b106e8f24bebd29f8b to your computer and use it in GitHub Desktop.
Save shreyakupadhyay/2b0c6a898c7e59b106e8f24bebd29f8b to your computer and use it in GitHub Desktop.
const widthPercentageToDP = widthPercent => {
const screenWidth = Dimensions.get('window').width;
const elemWidth = parseFloat(widthPercent);
return PixelRatio.roundToNearestPixel(screenWidth * elemWidth / 100);
};
const heightPercentageToDP = heightPercent => {
const screenHeight = Dimensions.get('window').height;
const elemHeight = parseFloat(heightPercent);
return PixelRatio.roundToNearestPixel(screenHeight * elemHeight / 100);
};
const proportionedPixel = designPixels => {
const screenProportion = Dimensions.get('window').width / 180;
return PixelRatio.roundToNearestPixel(designPixels * screenProportion);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment