是否执行以下操作:
<Text style={{color: 'blue', fontSize: 30}} />
与以下内容相比,有任何绩效影响:
<Text style={styles.blueButton} />
...
const styles = StyleSheet.create({
blueButton: {
color: 'blue',
fontSize: 30,
}
});
是否执行以下操作:
<Text style={{color: 'blue', fontSize: 30}} />
与以下内容相比,有任何绩效影响:
<Text style={styles.blueButton} />
...
const styles = StyleSheet.create({
blueButton: {
color: 'blue',
fontSize: 30,
}
});
从docs分到StyleSheet
分
性能:
- 从样式对象生成样式表可以通过ID引用它,而不是每次都创建一个新的样式对象.
- 它还允许只通过桥发送一次样式.(尚未实现所有后续使用).
另一个好处是,样式错误将在编译时而不是运行时生成.
我个人仍然喜欢使用内联样式(并为共享样式创建新组件),因为它使代码对我来说更具可读性,而且性能影响并不明显.