# react-native-fontext

> React native package for custom fonts

Latest version **0.1.8** (published 2021-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-fontext
pnpm add react-native-fontext
yarn add react-native-fontext
bun add react-native-fontext
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2021-11-12 |
| First published | 2021-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Vijay-mRoads |
| Maintainers | vijay-mroads, manu-mroads |
| Keywords | react-native, ios, android, react-native-fontext, react-native-fonts, hacktoberfest, hacktoberfest2021, lightweight, simple |

## Links

- npm: https://www.npmjs.com/package/react-native-fontext
- Repository: https://github.com/mroads/react-native-fontext
- Homepage: https://github.com/mroads/react-native-fontext#readme
- Issues: https://github.com/mroads/react-native-fontext/issues
- npm.io page: https://npm.io/package/react-native-fontext

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.8 (latest) — 2021-11-12
- 0.1.7 — 2021-10-13
- 0.1.6 — 2021-10-13
- 0.1.5 — 2021-10-13
- 0.1.3 — 2021-10-13
- 0.1.2 — 2021-10-12
- 0.1.1 — 2021-10-08

## README

# React Native Fontext

**react-native-fontext** is a lightweight library to integrate fonts in your React Native application that works seamlessly in android and iOS devices.

<p align="center">
  <img src="https://raw.githubusercontent.com/mroads/react-native-fontext/master/assets/images/fontext-font-change.gif" width="260">
</p>

# Setup

### Installation

`$ npm install react-native-fontext`

or

`$ yarn add react-native-fontext`

## Setup Instructions

1. Download and integrate fonts in your react-native application

   1. Download your preferred font from [Google Fonts](https://fonts.google.com) or any other font provider.

   2. Create a folder `fonts` in the root directory and place your downloaded fonts here. It is not mandatory to keep the `fonts` folder in the root directory but it is advised to keep it there for maintaining simplicity.
   3. Create a `react-native.config.js` file in the root directory of your project. This file is responsible for locating fonts' path so that react-native knows where to find them. The below code explains the content of the `react-native.config.js` file.

   ```js
   module.exports = {
     project: {
       ios: {},
       android: {},
     },
     assets: ['./fonts'],
   };
   ```

   4. In the terminal, write the command `npx react-native link` to link the fonts with your android and ios projects.
   5. Once linking is done, you can see the integrated fonts in Android (`android/app/src/main/assets/fonts`) and ios (`info.plist`).

2. Rebuild the project in Android and iOS projects and re-run the application.

## Props

inherits [Text Props](https://reactnative.dev/docs/text) from react-native. All the props that are available for React Native Text component are available for font-text Text component.

| Prop        |      Default      |       Type        | Description                                                             |
| :---------- | :---------------: | :---------------: | :---------------------------------------------------------------------- |
| computeFont |         -         |    `function`     | Function that calculates font family                                    |
| component   | React Native Text | `React.Component` | A custom component that can be passed to override the default component |

## Usage

- Install the package `react-native-fontext`

        npm install react-native-fontext

- Import the `Text` component from `react-native-fontext`

        import Text from react-native-fontext

- Use `fontFamily` and `fontWeight` to add fonts to your Text.

```js
textStyle: {
    fontFamily: 'NotoSansMono',
    fontWeight: '900',
  },
```

### Example: Adding font `Noto Sans`

```js
import React from 'react';
import { StyleSheet, View, Image } from 'react-native';
import logo from './assets/images/logo.png';

import Text from 'react-native-fontext';

const App = () => {
  return (
    <View>
      <Image source={logo} />
      <Text style={styles.text}>
        react-native-fontext gives you the ability to embed any font into your
        react native application.
      </Text>
    </View>
  );
};

const styles = StyleSheet.create({
  text: {
    // Add the following lines to add fonts in your Text component
    fontFamily: 'NotoSansMono',
    fontWeight: 'bold',
  },

  // Rest of the styles
});

export default App;
```

### Example: Using a Component prop

<p align="center">
  <img src="https://raw.githubusercontent.com/mroads/react-native-fontext/master/assets/images/fontext-buttonclick.gif" width="260">
</p>

```js
import React, { useState } from 'react';
import { StyleSheet, View, Image } from 'react-native';
import logo from './assets/images/logo.png';

import Text from 'react-native-fontext';
import { Button, Text as NBText } from 'native-base';

const COLORS = ['red', 'green', 'blue', 'orange', 'purple'];

const App = () => {
  const [color, setColor] = useState('black');

  const toggleColor = () => {
    let randomColor = COLORS[Math.floor(Math.random() * COLORS.length)];
    setColor(randomColor);
  };
  return (
    <View style={styles.container}>
      <Image source={logo} />
      <Text style={[styles.text, { color: color }]}>
        react-native-fontext gives you the ability to embed any font into your
        react native application.
      </Text>
      <Button>
        <Text
          onPress={toggleColor}
          component={NBText}
          style={styles.buttonText}
        >
          Toggle Color
        </Text>
      </Button>
    </View>
  );
};

const styles = StyleSheet.create({
  text: {
    // Add the following lines to add fonts in the text project
    fontFamily: 'NotoSansMono',
    fontWeight: 'bold',
    marginBottom: 60,
  },
  buttonText: {
    // Add the following lines to add fonts in the button's Text component
    fontFamily: 'NotoSansMono',
    fontWeight: '900',
  },

  // Rest of the styling
});

export default App;
```

---
_Source: https://npm.io/package/react-native-fontext · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
