Pixel–perfect, native–looking typographic styles for React Native. Why Creating great Text Styles in React Native is not a simple task, it requires a lot of fiddling and handling edge cases. This library provides a good set of defaults and helpers that cover the majority of the cases you'll need, make your code much simpler and ✨bonus✨ render great on iOS, Android and the web 😄 Quick start Add the dependency: Set a…
Pixel–perfect, native–looking typographic styles for React Native.
Why
Creating great Text Styles in React Native
is not a simple task,
it requires a lot of fiddling and handling edge cases.
This library provides a good set of defaults and helpers that cover the majority
of the cases you’ll need, make your code much simpler and ✨bonus✨ render
great on iOS, Android and the web 😄
Quick start
Add the dependency:
yarn add react-native-typography
Set a style in your component:
import { material } from 'react-native-typography'
<Text style={material.display1}>Hello Typography!</Text>
And it will look like this:
Demo app
You can run the included Demo Expo app, all of the screenshots are taken directly from there!
Typography collections
We provide a series of predefined collections for you to start with that match
the native design systems for iOS and Android.
You can use them directly wherever you would supply a
textStyle.
There’s also the option of extending them to create
your own styles.
A font weight in React Native is sometimes formed by a pair of a fontFamily and
a fontWeight, but not always! It depends on the typeface, sometimes it’s just
defined by the fontFamily.
With these helpers, you don’t have to worry about those inconsistencies.
To combine them with a collection style (or your own styles) just spread them,
as they are plain objects.
The San Francisco typeface defines its letter spacing via Kerning. This
is not compatible with the React Native text style properties, as they take
letter-spacing instead.
To perform this conversion on iOS you can use the sanFranciscoSpacing function, which
receives the font size and returns the appropriate letter spacing.
This is not needed for the web as the browsers already take care of this.
import { sanFranciscoSpacing } from 'react-native-typography'
const styles = StyleSheet.create({
customSize: {
..., // some other props
fontSize: 34,
letterSpacing: sanFranciscoSpacing(34),
},
});
This is already taken care of on the collections, but if you want to define your
own sizes you can adjust the spacing on iOS with this helper.
The default typeface on iOS is San Francisco. Using this typeface is the
easiest way to implement accessibility features like Dynamic Type. Using other
typefaces may require making adjustments to get the same accessibility
features.
This is the approach that we like to follow, and all the collections exported
from this library render nicely on all the supported platforms with their respective native
typefaces, for that we use the System weight helper.
You can check the code of the example app where we included a
couple of screens that follow this philosophy, this is how they render on iOS and Android:
F.A.Q.
But I don’t wanna use the Material Design or Human Interface Guidelines! Is there any reason why I should use this library?
Kerning is not 100% accurate on the Display sizes for the Material styles on Android
There’s no support for letter spacing on React Native Android yet. ☹️
Where is Roboto Black?
It’s not available by default on React Native Android yet. 😐
Why are there less weights available for CJK(Chinese, Japanese, Korean) languages on Android than iOS?
Android uses Noto Sans CJK (also known as Source Han Sans) to render those
languages, and
even though it has seven weights,
they’re not shipped with Android. 😕
There are some issues tracking this already, hopefully they will be included in
the future.
评论