Skip to content

Instantly share code, notes, and snippets.

@ankurg22
Created May 31, 2020 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ankurg22/edbff5cdb9be6e1dd34d8be7920738c0 to your computer and use it in GitHub Desktop.
Save ankurg22/edbff5cdb9be6e1dd34d8be7920738c0 to your computer and use it in GitHub Desktop.
React native responsive layout
/*
* Author: Ankur Gupta(ankurg22)
*/
import {
widthPercentageToDP as wp2dp,
heightPercentageToDP as hp2dp,
} from 'react-native-responsive-screen';
/**
* Width-Percentage
* Converts width dimension to percentage
* 360, 760 - design were made using this scale
* @param dimension directly taken from design wireframes
* @returns {string} percentage string e.g. '25%'
*/
export const wp = dimension => {
return wp2dp((dimension / 360) * 100 + '%');
};
/**
* Height-Percentage
* Converts width dimension to percentage
* * 360, 760 - design were made using this scale
* @param dimension directly taken from design wireframes
* @returns {string} percentage string e.g. '25%'
*/
export const hp = dimension => {
return hp2dp((dimension / 760) * 100 + '%');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment