Last active
September 1, 2022 11:36
-
-
Save byteab/81470643f51485cb884a96c8619b6b66 to your computer and use it in GitHub Desktop.
React Native Responsive Utility Functions
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 { Dimensions } from 'react-native'; | |
const { height: screenHeight, width: screenWidth } = Dimensions.get('window'); | |
const EACH_HEIGHT_UNIT = screenHeight / 100 | |
const EACH_WIDTH_UNIT = screenWidth / 100 | |
/** | |
* device height percentage | |
*/ | |
export const hp = (value) => EACH_HEIGHT_UNIT * value; | |
/** | |
* device width percentage | |
*/ | |
export const wp = (value) => EACH_WIDTH_UNIT * value; | |
export const clamp = (min, value, max) => { | |
if (value < min) { | |
return min; | |
} | |
if (value > max) { | |
return max; | |
} | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment