react native开发Android 篇——全局设置Text组件的属性详细代码
我一般写在index.js中。
/**
* @format
*/
import {AppRegistry,View,Text,StyleSheet} from 'react-native';
import React, { Component } from 'react';
import App from './App';
import {name as appName} from './app.json';
//属性设置开始
import _ from 'lodash';
//0.56(不包括)版本之前
/*Text.prototype.render = _.wrap(Text.render, function (func, ...args) {
let originText = func.apply(this, args)
return React.cloneElement(originText, {allowFontScaling: false,style:[
originText.props.style,
styles.defaultFontFamily
]})
})*/
//0.56(包括)版本之后
Text.render = _.wrap(Text.render, function (func, ...args) {
let originText = func.apply(this, args)
return React.cloneElement(originText, {allowFontScaling: false,style:[//allowFontScaling是text的字体大小不随系统字体大小的改变而改变
originText.props.style,
styles.defaultFontFamily
]})
})
var styles = StyleSheet.create({
defaultFontFamily:{//其他属性
}
})
//属性设置结束
AppRegistry.registerComponent(appName, () => App);