npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-fontext

v0.1.8

Published

React native package for custom fonts

Downloads

31

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.

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 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.

    module.exports = {
      project: {
        ios: {},
        android: {},
      },
      assets: ['./fonts'],
    };
    1. In the terminal, write the command npx react-native link to link the fonts with your android and ios projects.
    2. 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 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.

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

Example: Adding font Noto Sans

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

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;