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

@vitrion/react-native-load-fonts

v0.3.1

Published

test

Downloads

18,215

Readme

@vitrion/react-native-load-fonts

A powerful and flexible library that allows you to load fonts dynamically at runtime via base64 encoded TTF or OTF on your React Native application.

npm version MIT License Downloads Issues Pull Requests Last Commit Code Size TypeScript Version Forks

Screenshots

| iOS | Android | |:----------------------------:|:--------------------------------------------------------:| | iOS Screenshot | Android Screenshot |

Features

  • Load fonts dynamically at runtime
  • Support for TTF and OTF font formats
  • Base64 encoded fonts
  • Built with TypeScript

Installation

Install the package in your React Native project:

npm install @vitrion/react-native-load-fonts

Usage

To load a font dynamically, you must first have a base64 string of your font file (TTF or OTF):

import { loadFont, loadFonts, loadedFonts } from '@vitrion/react-native-load-fonts';

/* Load a single font */
loadFont('nameOfFont', base64FontString, 'ttf').then(function(name) {
	console.log('Loaded font successfully. Font name is: ', name);
});

/* Load a list of fonts */
loadFonts([{name: 'nameOfFont', data: base64FontString, type: 'ttf'}]).then(function(names) {
	console.log('Loaded all fonts successfully. Font names are: ', names);
});

console.log('Loaded fonts are: ', loadedFonts);
/* Be carefull this is not reactive, */

Font loading using file path

You can download font file to file system and then load it to app without sending base64 to bridge.

import { loadFontFromFile } from '@vitrion/react-native-load-fonts';
import RNFetchBlob from 'rn-fetch-blob'

const fontFilePath = RNFetchBlob.fs.dirs.DocumentDir + "fonts/roboto.ttf";

loadFontFromFile("Roboto",  fontFilePath)
   .then(function(name) {
   	    console.log('Loaded font successfully. Font name is: ', name);
   });

More examples can be found in the example directory of the repository.

iOS Screenshot

Functions

loadFont(name, data, type)

Options

| Option | iOS | Android | Info | |--------|----------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | name | Not used | Used | The name to be assigned to the loaded font. This parameter is used on Android to specify the registered font name (it doesn't work for iOS). | | data | Used | Used | The base64 string representation of the font file (TTF or OTF). It can be a data URI or raw base64. If it is raw base64, the type must be specified, but it defaults to TTF if not provided. The data URI should have a mime type of font/ttf or font/otf. | | type | Used | Used | (string, optional): Specifies the type of font in the encoded data. It should be either 'ttf' or 'otf'. Defaults to 'ttf'. |

The Response

The actual name the font was registered with. Use this name for your fontFamily.

Notes

  • Note for iOS: On iOS, it is not possible to explicitly specify the font name when loading fonts dynamically. As a result, both Android and iOS platforms will return the actual registered font name. For Android, this will be whatever you pass in, but for iOS, it will be the name embedded within the font file. To avoid any potential issues, it is recommended to always use the full font name embedded in the font file.

  • Ensuring Proper Display: It's important to note that the dynamically loaded font will only be displayed correctly if you provide the appropriate fontWeight and fontStyle values when applying the font. Be sure to refer to the provided example for guidance on using the correct font weight and font style configurations.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT