Skip to content

Instantly share code, notes, and snippets.

@AlexeyTsutsoev
Created March 16, 2023 07:54
Show Gist options
  • Save AlexeyTsutsoev/d00df825155c2bb8643067dbd96dc435 to your computer and use it in GitHub Desktop.
Save AlexeyTsutsoev/d00df825155c2bb8643067dbd96dc435 to your computer and use it in GitHub Desktop.
Scale for React Native Example
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