Skip to content

Instantly share code, notes, and snippets.

@ridvanaltun
Created August 24, 2022 00:53
Show Gist options
  • Save ridvanaltun/1115dcd5e7bb6d9c475ffa08d3155630 to your computer and use it in GitHub Desktop.
Save ridvanaltun/1115dcd5e7bb6d9c475ffa08d3155630 to your computer and use it in GitHub Desktop.
React-Native responsive design utils
import {widthPercentageToDP, heightPercentageToDP} from 'react-native-responsive-screen';
const REFERENCE_WIDTH = 428;
const REFERENCE_HEIGHT = 926;
export const wp = (val: number | string) => {
if (typeof val === 'number') {
return widthPercentageToDP(`${(100 * val) / REFERENCE_WIDTH}%`);
}
return widthPercentageToDP(val);
};
export const hp = (val: number | string) => {
if (typeof val === 'number') {
return heightPercentageToDP(`${(100 * val) / REFERENCE_HEIGHT}%`);
}
return heightPercentageToDP(val);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment