Created
October 22, 2018 12:24
-
-
Save xkrsz/d66f7fc2545bb7db8fad4626e396c4c7 to your computer and use it in GitHub Desktop.
RN responsive font sizes
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, Platform, PixelRatio } from 'react-native' | |
const { width: SCREEN_WIDTH } = Dimensions.get('window') | |
// based on iphone 5s's scale | |
const scale = SCREEN_WIDTH / 320 | |
export function normaliseSize(size) { | |
const newSize = size * scale | |
if (Platform.OS === 'ios') { | |
return Math.round(PixelRatio.roundToNearestPixel(newSize)) | |
} | |
return Math.round(PixelRatio.roundToNearestPixel(newSize)) - 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment