Last active
December 10, 2017 07:53
-
-
Save yayanartha/e7d39c122ad246cd87b2b0feca7fe832 to your computer and use it in GitHub Desktop.
A proper way to keep the 'ideal size' of components and fonts across screen dimensions.
This file contains hidden or 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'; | |
// Guideline sizes are based on standard ~5" screen mobile device | |
const guidelineBaseWidth = 350; | |
const guidelineBaseHeight = 680; | |
const scale = (size, screen = Dimensions.get('window')) => { | |
return screen.width / guidelineBaseWidth * size; | |
}; | |
const verticalScale = (size, screen = Dimensions.get('window')) => { | |
return screen.height / guidelineBaseHeight * size; | |
}; | |
const moderateScale = (size, factor = 0.5) => { | |
return size + (scale(size) - size) * factor; | |
}; | |
export { scale, verticalScale, moderateScale }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, thanks helpful mate (y)