How to disable font scaling in RN for Android?

Just using allowFontScaling={false} fixes it on iOS, but I'm not sure how to install it on Android.

Also, for those who are not familiar with RN and come here from the Android tag, I don’t think I can easily change it to dp font scaling or something else, so that I can do it globally in my application as- then?

Thanks!

+5
source share
1 answer

Update the file ManiApplication.java

 import android.view.WindowManager; import android.content.res.Configuration; import android.content.Context; import android.util.DisplayMetrics; 

After super.onCreate(); method put adjustFontScale(getApplicationContext(),getResources().getConfiguration());

Properly

  @Override public void onCreate() { super.onCreate(); adjustFontScale(getApplicationContext(),getResources().getConfiguration()); } 

And at the end add the following function

 public void adjustFontScale(Context context, Configuration configuration) { if (configuration.fontScale != 1) { configuration.fontScale = 1; 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); } } 
+4
source

Source: https://habr.com/ru/post/1244949/


All Articles