【发布时间】:2017-07-19 09:55:40
【问题描述】:
我今天遇到了一个问题。我想确保我的应用看起来不错,这需要我进行大量调整,尤其是在边距/填充部分。
我的问题是:哪种方法更好?创建多个样式表(在父组件上)只是为了适应这些小变化(我正在使用具有无边距样式表的可重用组件,这些边距将从父组件继承)或者只是让它内联在组件上?
我知道创建样式表可能是更好的方法。但是为了适应继承的样式,我将使用
style={[myComponentStyle, passedDownParentStyle]}
有这方面的专家能给我一些见解吗?
编辑 示例:
const Style = Stylesheet.create({
child: {
color: 'red'
},
parent1: {
padding: 5,
margin: 10
},
parent2: {
padding: 10,
margin: 5
}
})
class Child {
render() {
return (
<Text style={[Style.child, this.props.style]}>
{this.props.children}
</Text>
)
}
}
class Parent1 {
render() {
return (
<Child style={Style.parent1}>
Hello
</Child>
)
}
}
class Parent2 {
render() {
return (
<Child style={Style.parent2}>
World
</Child>
)
}
}
更新
我的问题是:style={[Style.child, this.props.style]} 的使用不是使 Stylesheet.create 的目的无效吗?我不应该根本不使用它吗?
【问题讨论】: