React native React Native:自定义文本组件在Android中不呈现(在iOS上工作正常)

React native React Native:自定义文本组件在Android中不呈现(在iOS上工作正常),react-native,react-native-android,React Native,React Native Android,我有一个自定义组件,它只是一个文本组件,接收各种样式的道具。它在iOS上运行得很好,但在Android上,该组件的文本不会显示出来 这是组件的代码: import React, { Component } from 'react'; import { Text, StyleSheet } from 'react-native'; export default class TextLabel extends Component { render() { const colors

我有一个自定义组件,它只是一个文本组件,接收各种样式的道具。它在iOS上运行得很好,但在Android上,该组件的文本不会显示出来

这是组件的代码:

import React, { Component } from 'react';
import { Text, StyleSheet } from 'react-native';

export default class TextLabel extends Component {
    render() {
    const colors = {
        red: '#CF243E',
        lightRed: '#E9BBC0',
        white: '#FFFFFF',
        default: '#434A54'
    }

    const weights = {
        bold: 'Raleway-Bold',
        default: 'Raleway-Regular'
    }

    const styles = StyleSheet.create({
        textStyles: {
            fontFamily: this.props.weight ? weights[this.props.weight] : weights.default,
            fontSize: this.props.size ? this.props.size : 16,
            textTransform: this.props.case ? this.props.case : 'none',
            color: this.props.color ? colors[this.props.color] : colors.default
        },
        additionalStyles: this.props.additionalStyles ? this.props.additionalStyles : {}
    })

    return (
        <Text style={[styles.textStyles, styles.additionalStyles]}>

            {this.props.children}

        </Text>
    );
}
}
import React,{Component}来自'React';
从“react native”导入{Text,StyleSheet};
导出默认类TextLabel扩展组件{
render(){
常量颜色={
红色:“#CF243E”,
浅红色:“#E9BBC0”,
白色:“#FFFFFF”,
默认值:“#434A54”
}
常数权重={
粗体:“雷威粗体”,
默认值:“Raleway常规”
}
const styles=StyleSheet.create({
文本样式:{
fontFamily:this.props.weight?权重[this.props.weight]:weights.default,
fontSize:this.props.size?this.props.size:16,
textTransform:this.props.case?this.props.case:“无”,
颜色:this.props.color?颜色[this.props.color]:colors.default
},
additionalStyles:this.props.additionalStyles?this.props.additionalStyles:{}
})
返回(
{this.props.children}
);
}
}
然后我在其他组件中使用它:

import React, { Component } from 'react';
import { View } from 'react-native';

import TextLabel from '../UI/TextLabel';

export default class Resolution extends Component {
render() {
    return (
        <View style={styles.wrapper}>

            <TextLabel
                size={21}
                weight={'bold'}
                additionalStyles={{ marginTop: 30, marginBottom: 10, textAlign: 'center'}}
            >
                Some random text
            </TextLabel>

        </View>
    );
}
}
import React,{Component}来自'React';
从“react native”导入{View};
从“../UI/TextLabel”导入TextLabel;
导出默认类解析扩展组件{
render(){
返回(
一些随机文本
);
}
}
但在安卓系统上,它不会渲染文本,而在iOS上,它工作得非常完美。会发生什么事


提前感谢。

事实证明,这是由于使用了textTransform属性,该属性目前在Android上存在一个漏洞,如果您在组件样式中设置该属性,则会导致文本消失

目前的解决方案是要么不使用它,要么使用string.toUpperCase()作为解决方法


有关此错误的更多信息,请点击此处:

是关于字体的吗?@adnbsr不这么认为,因为我在另一个组件(单选按钮)中使用了自定义字体,该组件包含文本,但不是此文本标签,并且工作正常。我会尝试删除代码以确定导致消失的部分。从CSSIf开始,如果你解决了它。加上你自己的答案。可能对未来的人有用future@dan-克拉森刚刚做了,直到两天才能把它作为一个答案,但到时候会做的。