react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Text] font size is changing

Open aprilzero opened this issue 11 years ago • 43 comments

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

aprilzero avatar Sep 01 '15 22:09 aprilzero

:+1:

myusuf3 avatar Sep 01 '15 22:09 myusuf3

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,
  };
};

ide avatar Sep 01 '15 23:09 ide

Was wondering the same thing @aprilzero. Thanks for the allowFontScaling it resolved my issues.

yamill avatar Sep 02 '15 00:09 yamill

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.

aprilzero avatar Sep 02 '15 02:09 aprilzero

Yeah that's fair. @a2 do you have thoughts on this?

ide avatar Sep 02 '15 02:09 ide

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.

a2 avatar Sep 02 '15 08:09 a2

Ah so I guess this a bug. I can submit a quick PR.

yamill avatar Sep 02 '15 13:09 yamill

I submitted a PR for this - https://github.com/facebook/react-native/pull/2530

yamill avatar Sep 02 '15 20:09 yamill

@yamill :+1:

myusuf3 avatar Sep 03 '15 01:09 myusuf3

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: accessibility

vjeux avatar Sep 07 '15 19:09 vjeux

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 avatar Sep 13 '15 21:09 ccheever

@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.

brentvatne avatar Sep 14 '15 02:09 brentvatne

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.

GantMan avatar Dec 23 '15 18:12 GantMan

Good point @GantMan - can you create an issue on ProductPains for this?

brentvatne avatar Dec 23 '15 21:12 brentvatne

consider it done!

GantMan avatar Dec 23 '15 22:12 GantMan

I found a solution,Text.defaultProps.allowFontScaling=false, it works, it is global

12d avatar Jun 15 '16 06:06 12d

12d, Please give me example for Text.defaultProps.allowFontScaling=false

uc-hus avatar Sep 18 '16 16:09 uc-hus

@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 👍

GantMan avatar Sep 18 '16 19:09 GantMan

Gant, Please provide a example!

uc-hus avatar Sep 19 '16 15:09 uc-hus

@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

GantMan avatar Sep 25 '16 18:09 GantMan