Skip to content

Instantly share code, notes, and snippets.

@Stringsaeed
Last active February 19, 2022 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stringsaeed/0cf247fdebe88008ac8b7195ec4e671d to your computer and use it in GitHub Desktop.
Save Stringsaeed/0cf247fdebe88008ac8b7195ec4e671d to your computer and use it in GitHub Desktop.
Create a pixel perfect design in react native
import {Dimensions} from 'react-native';
const {height: SCREEN_HEIGHT, width: SCREEN_WIDTH} = Dimensions.get('window');
const designSize = {width: 390, height: 844};
const CURRENT_RESOLUTION = Math.sqrt(
SCREEN_HEIGHT * SCREEN_HEIGHT + SCREEN_WIDTH * SCREEN_WIDTH,
);
const DESIGN_RESOLUTION = Math.sqrt(
designSize.height * designSize.height + designSize.width * designSize.width,
);
const RESOLUTIONS_PROPORTION = CURRENT_RESOLUTION / DESIGN_RESOLUTION;
export const getDesignSize = (size: number) => {
'worklet';
return RESOLUTIONS_PROPORTION * size;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment