vitalets / react-native-extended-stylesheet

Extended StyleSheets for React Native
MIT License
2.93k stars 132 forks source link

[ios] maxFontSize style property. #43

Closed vaukalak closed 7 years ago

vaukalak commented 7 years ago

On ios it's possible to change font scale in accessibility settings. Right now you can control if to allow the font scaling at all in the specific text component. anyway you can't set the max scale value for that text. Hopefully there's pixel ratio api which seems to allow query for current font scale.

That said, I think there should be an Api to set the max font size in the specific text field:

{
  fontSize: '1rem',
  maxFontSize: '2rem',
}

Which should be equivalent of

{
  fontSize: `1rem * {Math.min(2, PixelRatio.getFontScale())}`,
}

Thanks.

vitalets commented 7 years ago

hi @vaukalak ,

so the goal is to limit font scaling, correct? Maybe just support allowFontScaling for Android instead of introducing maxFontSize (that does not present in RN and may confuse people) ?

vaukalak commented 7 years ago

hey @vitalets, Right now my issue is on ios, and allowFontScaling will just on / off possibility to scale fonts in user preferences. I'd like to provide a functionality that will allow to limit scaling. right now on ios user can select x4 scale for fonts, wich breaks layout. I'd like to have API that will mention: allow to scale up this text component, but until certain value. this could be probably called maxFontScale instead of maxFontSize thoughts?

vitalets commented 7 years ago

I got the point. I think using value as a function should do exactly that:

{
  fontSize: () => EStyleSheet.value('1rem') * Math.min(2, PixelRatio.getFontScale())
}
vaukalak commented 7 years ago

@vitalets yeah, but I think it's gonna be something like:

const scaledFont = (value, maxScale = PixelRatio.getFontScale()) => {
  const calculated = EStyleSheet.value(value);
  return calculated / (PixelRatio.getFontScale() / maxScale);
}

Do you want that in your lib, or you think that should be a separate module?

vitalets commented 7 years ago

For me it looks more as separate module until we get many requests for that.