Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding default font sizes in React Native

I've been working on a React Native app for the past few months, and something has always eluded me that I'm just now trying to get to the bottom of. I'm trying to standardize the font sizes within my app (for body, headers, etc.) and am struggling to understand where exactly React Native gets its default font size from. I've been testing in an iPhone 8 simulator running iOS 11, and through experimentation have come to the conclusion the default font displayed is 14 logical pixels (as in a brand-new element with no styling). However, checking the iOS style guidelines it would seem the default body text on iOS is intended to be 17pt. Although I don't a ton about device scaling, I've tried crunching the numbers in every online converter I could find, and could not come up with how 17pt may come close to 14 logical pixels (assuming RN uses the body font size by default). The only way I was able to roughly translate the two was if the DPI was around 90, but the DPI for iPhones is much, much higher. So might anyone be able to offer insight as to how default fonts are selected in React Native? Even hunting through the source code I couldn't find much. I'd like to be able to calculate the base size myself so I can scale the other font sizes according. Thanks in advance!

like image 449
Nickersoft Avatar asked Oct 17 '17 15:10

Nickersoft


People also ask

What is the default size value for text?

The default text size in browsers is 16px. So, the default size of 1em is 16px.


1 Answers

I suggest you to look at react-native-element's helper method normalizeText. It calculates the pixel ratio and set the texts fontSize accordingly.

Also you should also take in consideration of Accessibility Text Size Option in iOS. This option will be affecting all your app.

like image 120
bennygenel Avatar answered Nov 15 '22 05:11

bennygenel