HarmonyOS WaterFlow组件使用sections进行布局,删除某一项之后布局计算异常

WaterFlow组件使用sections进行布局,删除某一项之后UI可以正常刷新,sections通过日志也能判断,已经重新计算。但是界面必须通过进行一次滑动操作之后才能显示正常。

HarmonyOS
2025-01-09 16:28:26
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

排查删除item时有没有sections.update,参考示例如下:

let index = this.dataSource.getIndexOfData(item);
this.dataSource.deleteItem(index);
this.oneColumnSection.itemsCount = this.oneColumnSection.itemsCount - 1;
this.sections.update(0, this.oneColumnSection)
  • 1.
  • 2.
  • 3.
  • 4.

问题根因WaterflowSections实例必须使用@State修饰,否则WaterflowSections update不会触发UI更新。将WaterflowSections实例定义在ViewModel中,规避方案:

private pageModal: PageModal = new PageModal();
@State sections: WaterFlowSections = this.pageModal.sections; // 从PageModal中取出sections,并用@State修饰
  • 1.
  • 2.
分享
微博
QQ
微信
回复
2025-01-09 20:01:28
相关问题
HarmonyOS 怎么删除cookie里某一项
710浏览 • 1回复 待解决
自定义Grid布局间距异常
309浏览 • 0回复 待解决
HarmonyOS 计算多行文本布局宽高
766浏览 • 1回复 待解决
HarmonyOS 删除相册中的某一照片
971浏览 • 1回复 待解决
ArkTS布局组件实现瀑布流式布局
1771浏览 • 1回复 待解决