Reputation: 106
I'm new in react-native and want to fix text size in all screens of app if I increase text size from device settings then also font size of should be same I had tried:
Text.defaultProps.allowFontScaling=false;
in android.index.js and
public void adjustFontScale(Context context, Configuration configuration) {
configuration.fontScale =(float) 0.85;
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(metrics);
metrics.scaledDensity = configuration.fontScale * metrics.density;
context.getResources().updateConfiguration(configuration, metrics);
}
in mainactivity.js called in oncreate()
after super.onCreate();
and also custom theme linked from AndroidManifest.xml not worked
if someone is having another solution for this please help me.
its working perfectly on ios device.
Upvotes: 1
Views: 8148
Reputation: 3904
(Should be a comment, but I haven't the rep!)
Seems to be some bugs with the Font Scaling, take a look at a few issues here:
https://github.com/facebook/react-native/issues/18827
Someone comments:
Also in React Native 0.56.0 setting TextInput.defaultProps.allowFontScaling = false; doesn't work at all.
There is a library someone has created for this issue, however I have not tested this:
https://github.com/NelGarbuzova/react-native-stylized-placeholder
UPDATE : I've tested this on my Android emulator and it works as below:
"react": "16.3.0-alpha.0",
"react-native": "0.55.0",
public render() {
return (
<View>
<Text allowFontScaling={false}>Text Scaling</Text>
<Text>No Text Scaling</Text>
</View>
)
}
The Result is below on a Pixel 2 (running 28)
Upvotes: 5