React-native-elements: Font size normalization across pixel ratios

Created on 13 Oct 2016  路  3Comments  路  Source: react-native-elements/react-native-elements

Font sizes on iphone6 and iphone4 are particularly small. It would be good to use a "resizing" function to help with this across pixel ratios.

If you would like me to submit a PR please let me know.

const React = require('react-native')
const {
PixelRatio
} = React;
const pixelRatio = PixelRatio.get();

const normalize = (size) => {
if (pixelRatio == 2) {
return size * 1.15;
}
if (pixelRatio == 3) {
return size * 1.35;
}
return size * pixelRatio;
}

export default normalize;

Usage:
import normalize from '../helpers/normalizeText';

fontSize: normalize(14)

Code example from: https://jsfiddle.net/97ty7yjk/ and https://stackoverflow.com/questions/34837342/font-size-on-iphone-6s-plus.

Most helpful comment

@xiaoneng How did you come to the numbers 1.15 and 1.35 for pixel ratios 2 and 3, respectively? They seem arbitrary

All 3 comments

Hello @xiaoneng , this would be a great addition for the project. Feel free to go ahead and submit a pr if you have the time, if not I will put this on my todo list! Thanks.

@xiaoneng How did you come to the numbers 1.15 and 1.35 for pixel ratios 2 and 3, respectively? They seem arbitrary

This was to scratch my own itch and meant as a starter for covering the gamut of pixel ratios / screen sizes combos out there. By all means fork, fix, pull request.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

binzailani3136 picture binzailani3136  路  3Comments

kk412027247 picture kk412027247  路  3Comments

vbagustinus picture vbagustinus  路  3Comments

iRoachie picture iRoachie  路  3Comments

kyleatblackfoot picture kyleatblackfoot  路  3Comments