为了简化代码并将道具传递给我的样式,我想出了这种解决方法
const styles = StyleSheet.create({
someNormalStyle: {
backgroundColor: 'red',
},
dynamicStyle(color) {
return {
backgroundColor: color
}
}
})
然后我通常会在我的组件中使用
<View style={style.someNormalStyle} />
<View style={style.dynamicStyle('blue')} />
这似乎可行,我只是想验证这样做是否会对性能产生影响?
答案 0 :(得分:1)