Created
March 16, 2023 07:54
-
-
Save AlexeyTsutsoev/d00df825155c2bb8643067dbd96dc435 to your computer and use it in GitHub Desktop.
Scale for React Native Example
This file contains 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 scale = Dimensions.get('window'); | |
/** | |
* width by Dimensions | |
*/ | |
export const DEVICE_WIDTH = scale.width; | |
/** | |
* height by Dimensions | |
*/ | |
export const DEVICE_HEIGHT = scale.height; | |
/** | |
* width by Figma | |
*/ | |
export const LAYOUT_WIDTH = 375; | |
/** | |
* height by Figma | |
*/ | |
export const LAYOUT_HEIGHT = 812; | |
/** | |
* Get scalable width by design | |
* @param size number | |
* @returns scaled width | |
*/ | |
export const scaleWidth = (size: number) => | |
Math.floor((DEVICE_WIDTH / LAYOUT_WIDTH) * size); | |
/** | |
* Get scalable height by design | |
* @param size number | |
* @returns scaled height | |
*/ | |
export const scaleHeight = (size: number) => | |
Math.floor((DEVICE_HEIGHT / LAYOUT_HEIGHT) * size); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment