question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Text] Auto adjust font size to fit Text node width.

See original GitHub issue

Hi! I’m looking for how I can achieve behavior similar to UILabel’s adjustsFontSizeToFitWidth=true, but haven’t been able to find anything.

Is this possible on a Text node?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:14
  • Comments:35 (11 by maintainers)

github_iconTop GitHub Comments

9reactions
Viral-Inccommented, Dec 20, 2017

how complicated is it to have adjustsFontSizeToFit work for Android too?

9reactions
wmoneckecommented, Sep 7, 2017

I managed to overcome this by doing the following.

  1. Pick the font size you like for the current view you have (Make sure it looks good for the current device you are using in the simulator).

  2. import { Dimensions } from 'react-native' and define the width outside of the component like so: let width = Dimensions.get('window').width;

  3. Now console.log(width) and write it down. If your good looking font size is 15 and your width is 360 for example, then take 360 and divide by 15 ( = 24). This is going to be the important value that is going to adjust to different sizes.

  4. Use this number in your styles object like so:

    textFontSize: { fontSize = width / 24 },...

Now you have a responsive fontSize.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make text fit its parent size using JavaScript
We can "try" to increase the font size step-wise by 1 pixel and test again, whether the element is overflowing it's parent or...
Read more >
React Native — How to center Text and auto adjust font size ...
4. Use allowFontScaling. Specifies whether fonts should scale to respect Text Size accessibility settings.
Read more >
Font size auto adjust to fit - javascript - Stack Overflow
This question might help you out but I warn you though this solves it through jQuery: Auto-size dynamic text to fill fixed size...
Read more >
[Text] Auto adjust font size to fit Text node width. - React Native
I intend to build this for Android, as my first foray into the react-native codebase, by mimicking the iOS implementation (and also watching...
Read more >
Resize to fit - Variable Fonts for Developers
Resize text to fit the parent with variable font width axis ... to fit its parent container, but it's been largely limited to...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found