Skip to content

Instantly share code, notes, and snippets.

@ehxxn
Last active September 1, 2022 11:36
Show Gist options
  • Save ehxxn/81470643f51485cb884a96c8619b6b66 to your computer and use it in GitHub Desktop.
Save ehxxn/81470643f51485cb884a96c8619b6b66 to your computer and use it in GitHub Desktop.
React Native Responsive Utility Functions
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