0

i want to change fontSize in textinput based on screen width in react native.

i want to make something like this, expected result is the fontSize go smaller when adding numbers to the textInput

Demo Expected Results

Resources i tried:

React Native Responsive Font Size

https://reactnativeexample.com/responsive-fontsize-based-on-screen-size-of-the-device-in-react-native/

and much more didn't work.

Balalen
  • 460
  • 6
  • 13

1 Answers1

1

You need to calculate relationship of text and container width together with letter spacing, margin etc.

fontsize = containerWidth / Math.max(text.length, 1) - adjustment

snack example here: https://snack.expo.io/PJeeBTGGe

Horst
  • 1,733
  • 15
  • 20