mrzachnugent / react-native-reusables

Universal shadcn/ui for React Native featuring a focused collection of components - Crafted with NativeWind v4 and accessibility in mind.
https://rnr-docs.vercel.app
MIT License
3.88k stars 157 forks source link

fix: dynamic font scaling support for inputs and buttons #284

Open hurshore opened 2 days ago

hurshore commented 2 days ago

Pull Request Template

Description:

This PR introduces a new useFontScale hook to address text scaling issues in buttons and inputs on iOS and Android. Currently, when users increase their device's font size settings, text can get cut off in UI elements since they don't scale accordingly.

The hook provides utilities to dynamically adjust component heights based on the system font scale, ensuring text remains visible and properly contained within UI elements. It uses React Native's useWindowDimensions to reactively update when system font settings change.

Fixes #219

Tested Platforms:

Affected Apps/Packages:

Screenshots:

  1. Input/button with default font scale

    Default font size input screenshot Large font size input screenshot
  2. Input/button with increased font scale

    Default font size screenshot Large font size screenshot

Notes:

Example usage in components:


const { getScaledHeight } = useFontScale();
const baseHeight = 48;
const baseFontSize = 16;

// Component height will now scale with system font size
const dynamicHeight = getScaledHeight(baseHeight, baseFontSize);
vercel[bot] commented 2 days ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
rnr-docs βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 23, 2024 10:19pm
rnr-showcase βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 23, 2024 10:19pm