Disabling font scaling can degrade the availability of your application, ideally if you want to limit the scaling for applications using React native 0.58.0 and higher; use maxFontSizeMultiplier
prop for specific Text
components.
However, if you absolutely want to disable font scaling throughout the application, you can do this globally by setting allowFontScaling
prop to defaultProps
in Text
.
For React Native 0.56. 0+
Text.defaultProps = Text.defaultProps || {}; Text.defaultProps.allowFontScaling = false;
For earlier versions of React Native, you only need the second line, but having both will not hurt. The first line simply protects the component Text
, not having defaultProps
, as in the case React Native 0.56.0 and above.
Add the above lines to the entry point file of your React Native application (usually index.js
, app.js
or main.js
) to apply this support to all Text
components in your application.
This attribute only affects the Text
components, and you can apply the same changes to TextInput
, which can be done using a similar fragment:
TextInput.defaultProps = TextInput.defaultProps || {}; TextInput.defaultProps.allowFontScaling = false;
Also note that some components do not obey the font scaling settings, for example: Alert
, PickerIOS
, DatePickerIOS
, TabBarIOS
, SegmentedControlIOS
, since all of them are initially drawn and are not dependent on the Text
components.
source share