Android:
修改 MainActivity.java 文件
import android.content.res.Configuration;
import android.content.res.Resources;
public class MainActivity extends ReactActivity {
...
// 禁止字體縮放
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics());
return res;
}
}
iOS
使用Text 的一個(gè)屬性 allowFontScaling={false}
但需要每個(gè)Text都要寫一個(gè)這個(gè)屬性,很麻煩,在不做封裝的情況下可以使用下面方法做全局設(shè)置:
在項(xiàng)目寫global變量的地方加入:
import { Text, TextInput } from 'react-native'
Text.defaultProps.allowFontScaling=false;
TextInput.defaultProps.allowFontScaling=false;
TextInput.defaultProps = Object.assign({}, TextInput.defaultProps, {allowFontScaling: false}); // 新版RN使用該方法替代
Text.defaultProps = Object.assign({}, Text.defaultProps, {allowFontScaling: false});
上面修改了全局的Text 、TextInput的allowFontScaling默認(rèn)值,如果項(xiàng)目使用了react-navigation,還需要修改 headerTitleAllowFontScaling = false ,參考API
如果引入了react-native-flux-router ,在Tab 節(jié)點(diǎn),加入allowFontScaling={false} 屬性,屏蔽掉導(dǎo)航欄和TabBar上的字體變大
<Tabs key="root" allowFontScaling={false} ......>