Created
August 24, 2022 00:53
-
-
Save ridvanaltun/1115dcd5e7bb6d9c475ffa08d3155630 to your computer and use it in GitHub Desktop.
React-Native responsive design utils
This file contains hidden or 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 {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