反应原生道具allowFontScaling无法在Android上运行

时间:2018-09-11 12:27:42

标签: android android-layout react-native react-redux main-activity

我是react-native的新手,如果我要从设备设置中增加文本大小,则想在应用程序的所有屏幕中修复文本大小,然后的字体大小也应该与我尝试过的相同,

Text.defaultProps.allowFontScaling=false;

在android.index.js中  和

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);

}

在super.onCreate()之后在oncreate()中调用的mainactivity.js中

以及从AndroidManifest.xml链接的自定义主题也无效

如果有人对此有其他解决方案,请帮助我。

它在ios设备上完美运行。

2 个答案:

答案 0 :(得分:3)

(应该是评论,但我没有代表!)

Font Scaling似乎是一些错误,请在此处查看一些问题:

https://github.com/facebook/react-native/issues/18827

有人评论:

  

也在React Native 0.56.0中设置TextInput.defaultProps.allowFontScaling = false;根本不起作用。

有人为此问题创建了一个库,但是我没有对此进行测试:

https://github.com/NelGarbuzova/react-native-stylized-placeholder

更新:我已经在Android模拟器上对此进行了测试,它的工作原理如下:

@hybrid_property
def max_size(self):
   return (
            db.session.query(func.max(Screen.height, Screen.width))
            .filter(Screen.id == self.id)
            .scalar()
        )

@max_size.expression
def max_size(cls):
    return (
            select([func.max(Screen.height, Screen.width)])
            .where(Screen.id == cls.id)
            .label("max_size")
        )

结果在像素2(运行28)下

enter image description here

答案 1 :(得分:-1)

围绕此问题提出了大约5个GitHub问题。 RN会继续淡化并关闭它们,而不是进行修复。