Skip to content

Commit

Permalink
make RFValue to get standardScreenHeight as param
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman333 committed Oct 24, 2019
1 parent 2812e77 commit 519020d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## react-native-responsive-fontsize
<img src="images/main.png" alt="main image">

# react-native-responsive-fontsize

[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/heyman333/react-native-responsive-fontSize/pulls)
[![Platform](https://img.shields.io/badge/platform-react--native-lightgrey.svg)](http://facebook.github.io/react-native/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/heyman333/react-native-responsive-fontSize/blob/master/LICENSE)

<strong>Use this library if you have a small problem with the font size 🎉</strong>

<img src="images/main.png" alt="main image">

<hr />

#### How to install
Expand All @@ -24,14 +24,21 @@ npm install react-native-responsive-fontsize --save
| :------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------: |
| <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"> |

#### Methods

| | arguments | Description |
| :----------: | :------------------------------------------: | :------------------------------------------------------------------------: |
| RFPercentage | percent: number | The font size is calculated as a percentage of the height of the device. |
| RFValue | value: number, standardScreenHeight?: number | The font size is determined based on standardScreenHeight and passed value |

#### Usage

```js
import { RFPercentage, RFValue } from "react-native-responsive-fontsize";

const styles = StyleSheet.create({
welcome: {
fontSize: RFValue(24),
fontSize: RFValue(24, 580) // second argument is standardScreenHeight(optional),
textAlign: "center",
margin: 10,
},
Expand All @@ -44,6 +51,10 @@ const styles = StyleSheet.create({
});
```

#### Changelog

[releases](https://github.com/heyman333/react-native-responsive-fontSize/releases)

#### Load map (I'm waiting for your help)

- [ ] support landscape mode
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare function RFPercentage(percent: number): number;
declare function RFValue(value: number): number;
declare function RFValue(value: number, standardScreenHeight: number): number;

export { RFPercentage, RFValue };
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export function RFPercentage(percent) {
return Math.round(heightPercent);
}

export function RFValue(fontSize) {
// guideline height for standard 5" device screen
const standardScreenHeight = 680;
// guideline height for standard 5" device screen is 680
export function RFValue(fontSize, standardScreenHeight = 680) {
const heightPercent = (fontSize * deviceHeight) / standardScreenHeight;
return Math.round(heightPercent);
}

0 comments on commit 519020d

Please sign in to comment.