文本样式的 react-native prop 类型 [英] react-native prop type for text style

查看:63
本文介绍了文本样式的 react-native prop 类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构简单的组件和一个 <Text> 树内某处,我想为其传递样式.除了 proptypes 验证之外,它完美无缺.

i have component with a simple structure and a <Text> somewhere inside the tree for which i want to pass in a style. Which works perfectly but for the proptypes validation.

基本设置还不止这些

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,
};

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

The problem is that the ViewPropTypes.style does not contain i.e. color key. So providing a style with a color is invalid and produces a warning. I tried to import TextStylePropTypes as i found in https://github.com/facebook/react-native/blob/master/Libraries/Text/TextStylePropTypes.js but it is undefined.

有什么建议吗?

推荐答案

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

For anybody trying to achieve this seems like View.propTypes.style is deprecated while Text.propTypes.style is not.

这篇关于文本样式的 react-native prop 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆