阵营母语:模块化造型
问题描述:
foo.js(代码块从阵营母语样板):阵营母语:模块化造型
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
什么是从一个不同的文件bar.js宣布新的风格的最佳方式是什么?
1)添加一个新的属性到styles
?
//import styles from 'foo.js'
styles.forNewComponent = {
fontSize: 30,
};
2)或者创建新的StyleSheet
obj?
const StylesforNewComponent = StyleSheet.create({
fontSize: 30,
});
当使用1)方法和console.log(styles);
输出是:
Object {container: 3, welcome: 4, instructions: 5, forNewComponent: Object}
为什么forNewComponent
的值是一个对象,但其他性能都ID
我做错了?我会有性能问题吗?
答
使用StyleSheet.create
代替普通对象。因为StyleSheet创建类似缓存的东西。
静态创建(OBJ) - 创建从给定对象样式表样式参考。
而当你使用StyleSheet
- 你会,如果你做错事的风格
警告,好的做法是1种成分= 1级的样式表
感谢您的解释! – Edgar
不客气。乐意效劳 ) –