import React, {Component} from ‘react‘;
import {Platform, StyleSheet, Text} from ‘react-native‘;
const defaultFontFamily = {
...Platform.select({
android: {fontFamily: ‘Roboto‘}
})
};
export default class ZTText extends Component {
constructor(props) {
super(props);
}
render() {
let myStyle = {includeFontPadding: false}
if (this.props.style) {
let tempStyle = this.props.style;
if (tempStyle.constructor == Number) {// 处理StyleSheet的样式
tempStyle = StyleSheet.flatten(tempStyle);
}
if (tempStyle.constructor == Array) {
tempStyle.forEach(styleInfo => {
let tempStyleInfo = styleInfo;
if (styleInfo.constructor == Number) {// 处理StyleSheet的样式
tempStyleInfo = StyleSheet.flatten(tempStyleInfo);
}
myStyle = {...myStyle, ...tempStyleInfo};
});
} else {
myStyle = {...myStyle, ...tempStyle};
}
}
let mergeStyle = {...defaultFontFamily, ...myStyle};
let myProps = {...this.props, style: mergeStyle};
return (< Text {...myProps}/>);
}
}
原文:https://www.cnblogs.com/hjj2ldq/p/13025277.html