Last active
December 1, 2018 06:27
-
-
Save kashishgrover/460049e1576ef834560627f4c89335d4 to your computer and use it in GitHub Desktop.
Centralized scaling algorithm for React Native
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
const { width, height } = Dimensions.get('window'); | |
const heightAspect = 568; | |
const widthAspect= 320; | |
const verticalScale = height / heightAspect; | |
const horizontalScale = width / widthAspect; | |
export const scale = (size) => (verticalScale / horizontalScale) * size; | |
export const scalePx = (sizePx) => { | |
const i = parseInt(sizePx, 10); | |
return `${scale(i)}px`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment