[Text] font size is changing
Just upgraded to 11-rc and all <Text> font sizes are now being affected by accessibility settings.
Accessibility is great, but this ended up breaking many of our screens. It seems like it would be better to opt into that behavior. Our app wasn't designed for that extreme variability in font size, and I imagine many others weren't either.
We fixed the issue for now by adding allowFontScaling={false} to every text node, but obviously that is verbose and not optimal. It would be great to either have that be default, or a documented way to set it just once globally.
I believe the relevant commit is at https://github.com/facebook/react-native/commit/53fb5b6cee50f85bc6220231b2fd39fd94b587db
:+1:
FWIW I believe honoring the accessibility settings should be the default for the same reasons why a web browser lets you magnify text if you want to. Looking at my phone's apps, most of the text is for content more than presentation.
Easiest way to do it globally is maybe to override the default props (untested):
import { Text } from 'react-native';
let originalGetDefaultProps = Text.getDefaultProps;
Text.getDefaultProps = function() {
return {
...originalGetDefaultProps(),
allowFontScaling: false,
};
};
Was wondering the same thing @aprilzero. Thanks for the allowFontScaling it resolved my issues.
I flipped through some of the top native apps on my phone—Facebook, Instagram, Snapchat, Uber, Calendar and Slack are fixed font sizes that do not follow the accessibility setting.
Others apps like Messenger, Twitter, Spotify, Mail scale the text based on the setting. Seems to be ones that are more text based and have a lot of reading.
IMHO it should be up to the app developer to decide which category their app falls into.
Yeah that's fair. @a2 do you have thoughts on this?
It seems that this changed in 53fb5b6cee50f85bc6220231b2fd39fd94b587db. The commit message says that allowFontScaling should be false by default but the code and UIExplorer example say otherwise.
Ah so I guess this a bug. I can submit a quick PR.
I submitted a PR for this - https://github.com/facebook/react-native/pull/2530
@yamill :+1:
IMHO it should be up to the app developer to decide which category their app falls into.
In my experience, if you do not have accessibility features baked by default, then no one will really implement it properly. We've done a lot of work with React Native to get voice over working well by default: any element that is <Touchable*> will be accessible and the hint will be a concatenation of all the text inside (if any). We absolutely should have font scaling be the default, and if it doesn't work well with some screens of your app, then you can disable it.
Also, I just tried and Facebook does update some text to be bigger with accessibility settings:

If this is the intended behavior can this issue be closed? Or is there more to do here? @aprilzero - maybe you could just make a NonScalingText component that wraps Text sets the prop such that the text doesn't scale?
@ccheever - I think you're right that this can be closed now, this option won't be changed -- defining your own Text component to reduce boilerplate seems like a solution where necessary.
I know this issue is closed, but I think we conflated two questions, and left the more important one discarded.
YES it should default to true, and because it's an option, it should be a simple global (not just per instance) for the developer to disable app-wide. @ccheever and @brentvatne please consider that as we utilize 3rd party node modules, we don't always have access to the underlying textviews to restructure them to a nonscaling text.
Good point @GantMan - can you create an issue on ProductPains for this?
consider it done!
I found a solution,Text.defaultProps.allowFontScaling=false, it works, it is global
12d, Please give me example for Text.defaultProps.allowFontScaling=false
@uc-hus - you could throw this in your index.ios.js just import text and modify it's defaultProps. Done! All subsequent uses of Text will have font scaling set to false. Super easy 👍
Gant, Please provide a example!
@uc-hus - I made a PR to Ignite to expose this option in AppSettings.js.
I hope this example helps: https://github.com/infinitered/ignite/pull/389