在React Native中可以通过setState实现刷新组件,setState会触发render()方法重新渲染,页面布局复杂的时候会遇到性能问题,React Native提供局部刷新组件的方法setNativeProps,使用如下
<View
ref={(c) => this.refView = c}>
</View>
在需要触发局部更新组件的事件中调用方法,通过组件引用调用组件的setNativeProps方法实现组件的局部刷新,组件自身的所用的属性都可以设置,这里示例只是刷新组件的backgroundColor,想要刷新组件的其他属性可自行添加和设置。
onPressEvent() {
this.refView.setNativeProps({
style: {backgroundColor: '#f1f1f1'}
});
}
105



被折叠的 条评论
为什么被折叠?



