用于文本样式的react-native prop类型

pat*_*man 11 react-native react-proptypes

我有一个结构简单的组件和<Text>树内的某个地方,我希望以一种风格传递.这对于proptypes验证非常有效.

基本设置不仅仅是这个

export default class Component extends PureComponent {
    render() {
        return (<View><Text style={this.props.style}>Some text</Text></view>);
    }
}

Component.defaultProps = {
    style: null,
};

Component.propTypes = {
    style: ViewPropTypes.style,
};
Run Code Online (Sandbox Code Playgroud)

问题是ViewPropTypes.style不包含ie color键.因此,提供带有颜色的样式无效并产生警告.我试图导入,TextStylePropTypes如我在https://github.com/facebook/react-native/blob/master/Libraries/Text/TextStylePropTypes.js中找到的,但它是未定义的.

关于该怎么做的任何建议?

pat*_*man 20

对于任何试图实现这一点的人来说,似乎View.propTypes.style已被弃用,而Text.propTypes.style不是.


Gal*_*sha 6

由于传递的样式道具用于文本节点,请使用Text.propTypes.style如下所示...

Component.propTypes = {
    style: Text.propTypes.style
};
Run Code Online (Sandbox Code Playgroud)