[Text] Auto adjust font size to fit Text node width.
See original GitHub issueHi! 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:
- Created 8 years ago
- Reactions:14
- Comments:35 (11 by maintainers)
Top 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 >
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
how complicated is it to have adjustsFontSizeToFit work for Android too?
I managed to overcome this by doing the following.
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).
import { Dimensions } from 'react-native'
and define the width outside of the component like so:let width = Dimensions.get('window').width;
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.Use this number in your styles object like so:
textFontSize: { fontSize = width / 24 },...
Now you have a responsive fontSize.