react-native-text
Version:
Scalable font size in Text component for React Native
81 lines (56 loc) • 1.74 kB
Markdown
on a device width.
This is the comparison of two screens (iPhone 4s and iPhone 6s Plus),
with applied style:
```js
welcome: {
fontSize: 31,
textAlign: 'center',
margin: 10,
},
instructions: {
fontSize: 16,
textAlign: 'center',
color: '#333333',
marginBottom: 5,
}
```
You can also check out the example usage on Snack: https://snack.expo.io/@knowbody/react-native-text-example


1. `yarn add react-native-text`
2. Example usage:
```js
import React, { PropTypes } from 'react';
import { StyleSheet } from 'react-native';
import ScalableText from 'react-native-text';
const WelcomeText = ({ text }) => <ScalableText style={styles.text}>{text}</ScalableText>;
const styles = StyleSheet.create({
text: {
color: 'tomato',
fontSize: 28,
},
});
export default WelcomeText;
```
Yes, you can! The `scaleText` function is a named export. Invoke it with the following signature:
```js
import { scaleText } from 'react-native-text';
const style = scaleText({
deviceBaseWidth: 375,
fontSize: 14,
lineHeight: 14 * 1.2,
}); // returns: { fontSize, lineHeight }
```
Or with a React Hook `useScaleText`:
```js
import { useScaleText } from 'react-native-text';
const { fontSize, lineHeight } = useScaleText({ fontSize: 18 });
```
MIT
React Native Text scales the font size based