Skip to content

Instantly share code, notes, and snippets.

@xkrsz
Created October 22, 2018 12:24
Show Gist options
  • Save xkrsz/d66f7fc2545bb7db8fad4626e396c4c7 to your computer and use it in GitHub Desktop.
Save xkrsz/d66f7fc2545bb7db8fad4626e396c4c7 to your computer and use it in GitHub Desktop.
RN responsive font sizes
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