【发布时间】:2016-08-05 04:07:53
【问题描述】:
我正在尝试为我的 React-Native 应用程序创建一些具有默认样式的可重用 UI 组件。
一个示例默认MyText(橙色,14,粗体):
import React, { Component, StyleSheet, Text } from 'react-native';
const styles = StyleSheet.create({text: {color: 'orange', fontSize: 14, fontWeight: 'bold'}});
export default class MyText extends Component {
render() {
return <Text style={styles.text}>{this.props.children}</Text>
}
}
我想如何使用它:
import Text from '../ui/myText';
...
<Text style={{color: 'black'}}>My custom styled text, but in black instead of orange</Text>
...
有没有办法做到这一点?显然,如果我尝试访问this.props.style,它只会返回一个已编译样式表的 ID。
【问题讨论】:
标签: react-native