Created
June 25, 2022 15:01
-
-
Save gys-dev/ff1c5771b1a140e393724205b36ee914 to your computer and use it in GitHub Desktop.
Resposive
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, PixelRatio } from 'react-native' | |
const guidelineBaseWidth = 390 | |
const guidelineBaseHeight = 844 | |
const { height, width } = Dimensions.get('window') | |
/** | |
* | |
* @param size: fontSize of text | |
* @returns re-calculate fontSize of text | |
*/ | |
export function normalize(fontSize: number): number { | |
const scale = width / guidelineBaseWidth | |
const newSize = fontSize * scale | |
return Math.round(PixelRatio.roundToNearestPixel(newSize)) | |
} | |
/** | |
* | |
* @param size: width of element | |
* @returns re-calculate width of element | |
*/ | |
export function scale(size: number): number { | |
return (width / guidelineBaseWidth) * size | |
} | |
/** | |
* | |
* @param size: height of element | |
* @returns re-calculate height of element | |
*/ | |
export function verticalScale(size: number): number { | |
return (height / guidelineBaseHeight) * size | |
} | |
export function moderateScale(size: number, factor: number = 0.5): number { | |
return size + (scale(size) - size) * factor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment