react-native-responsive-fontsize
Version:
Simple method for resposive fontSize based on screen-size of the device in React-Native
72 lines (53 loc) • 3.51 kB
Markdown
<img src="images/main.png" alt="main image">
[](https://github.com/heyman333/react-native-responsive-fontSize/pulls)
[](http://facebook.github.io/react-native/)
[](https://github.com/heyman333/react-native-responsive-fontSize/blob/master/LICENSE) [](https://greenkeeper.io/)
<a href="https://www.npmjs.com/package/react-native-responsive-fontsize">
<img alt="npm version" src="http://img.shields.io/npm/v/react-native-responsive-fontsize.svg?style=flat-square">
</a>
<a href="https://www.npmjs.com/package/react-native-responsive-fontsize">
<img src="http://img.shields.io/npm/dm/react-native-responsive-fontsize.svg?style=flat-square">
</a>
<strong>Use this library if you have a small problem with the font size 🎉</strong>
<hr />
```shell
yarn add react-native-responsive-fontsize
npm install react-native-responsive-fontsize --save
```
| iPhone SE | iPhone X |
| :------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: |
| <img src="https://raw.githubusercontent.com/heyman333/react-native-responsive-fontSize/master/images/SE.png" width="320" height="568"> | <img src="https://raw.githubusercontent.com/heyman333/react-native-responsive-fontSize/master/images/X.png" width="385" height="812"> |
| | arguments | Description |
| :----------: | :------------------------------------------: | --------------------------------------------------------------------------------------------------- |
| RFPercentage | percent: number | The font size is calculated as a percentage of the height(`width` in landscape mode) of the device. |
| RFValue | value: number, standardScreenHeight?: number | The font size is calculated based on standardScreenHeight and passed value |
- when using `RFValue`'s `standardScreenHeight`
- default standardScreenHeight is `680`
- In landscape mode, please pass the `screen width`
#### Usage
```js
import { RFPercentage, RFValue } from "react-native-responsive-fontsize";
const styles = StyleSheet.create({
welcome: {
fontSize: RFValue(24, 580) // second argument is standardScreenHeight(optional),
textAlign: "center",
margin: 10,
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5,
fontSize: RFPercentage(5),
},
});
```
[](https://github.com/heyman333/react-native-responsive-fontSize/releases)
- [x] support landscape mode
- [x] make `test code`