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-adaptive-fontsize

v1.0.1

Published

A React Native utility for responsive font sizes with support for Android 14 font scaling.

Downloads

119

Readme

React Native Responsive Font Size

react-native-adaptive-fontsize is a utility for React Native that helps you create responsive font sizes that adapt to the user's system settings, particularly in environments like Android 14, where users have more control over font scaling. This package is designed to prevent common issues that arise from excessive font scaling, ensuring your app's UI remains consistent and user-friendly.

Problem Statement

With the introduction of enhanced font scaling options in Android 14, users can significantly alter the font size across their devices. While this improves accessibility, it also poses challenges for app developers:

  • UI Breakage: Excessive font scaling can lead to text truncation, overlapping UI elements, and other layout issues, negatively affecting the user experience.
  • Inconsistent Appearance: Different devices may render text sizes inconsistently, leading to a fragmented user experience.
  • Accessibility vs. Usability: Balancing accessibility features like font scaling with maintaining a clean and usable interface can be challenging.

react-native-adaptive-fontsize solves these problems by:

  • Capping Font Sizes: Allows you to set minimum and maximum font sizes, ensuring text remains readable without breaking the UI.
  • Adaptive Scaling: Automatically adjusts font sizes based on the device’s font scale settings while respecting your defined constraints.
  • Consistency Across Devices: Ensures that your app maintains a consistent look and feel, regardless of the user's font size preferences.

Installation

You can install the package using npm:

npm install react-native-adaptive-fontsize

Usage

Here are two examples demonstrating how to use react-native-adaptive-fontsize in your React Native project:

  • Example 1: Basic Usage Without Min/Max Constraints This example shows how to use the responsiveFont function without specifying maxFontSize and minFontSize. The font size will scale freely based on the device's settings.
import { responsiveFont } from 'react-native-adaptive-fontsize';
import { StyleSheet, Text, View } from 'react-native';

const App = () => {
  return (
    <View style={styles.container}>
      <Text style={styles.text}>Responsive Font Example</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    fontSize: responsiveFont(16), // Base size 16, scales freely
  },
});

export default App;
  • Example 2: Usage with Min/Max Constraints This example shows how to use the responsiveFont function with specified maxFontSize and minFontSize parameters. This ensures the font size remains within the defined range:
import { responsiveFont } from 'react-native-adaptive-fontsize';
import { StyleSheet, Text, View } from 'react-native';

const App = () => {
  return (
    <View style={styles.container}>
      <Text style={styles.text}>Responsive Font Example</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text: {
    fontSize: responsiveFont(16, 24, 12), // Base size 16, max size 24, min size 12
  },
});

export default App;

Parameters

  • fontSize: number: The base font size that you want to scale.
  • maxFontSize?: number: Optional. The maximum allowed font size after scaling. If not provided, the font size can scale freely upwards.
  • minFontSize?: number: Optional. The minimum allowed font size after scaling. If not provided, the font size can scale freely downwards.

Why Use react-native-adaptive-fontsize?

With react-native-adaptive-fontsize, you can:

  • Maintain UI Integrity: Prevent your app’s UI from breaking due to large or small text sizes.
  • Enhance Accessibility: Respect user preferences for font size adjustments while ensuring your app remains usable and visually appealing.
  • Simplify Development: Easily manage responsive typography without manually calculating sizes or worrying about device-specific issues.

This package is particularly useful for developers targeting Android 14 and newer, where system-wide font scaling is more granular and can have a significant impact on app layouts.

Contributing

Contributions are welcome! If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.