🌚

Kam's Online Notebook


Don't trust  beta software

出于写技术分享的原因去验证了下 iOS 15 上对 diffable data source 两个 API 的改进,有些情况比较尴尬。

apply & reconfigureItems

WWDC 2021 Session 10252 - Make blazing fast lists and collection views 提到说 iOS 15 之后,调用 apply(_:animatingDifferences:completion:) without animation 可以从过去的 reloadData提升到 diff 局部刷新,然后新增 reconfigureItems(_:) 实现 on-cell reloading,这不偷了两年懒才整出来的活儿吗哈哈?

但是比较尴尬的时候,我弄了个 demo 测试着两个 API 的变化,结果在 remove/reconfig item 之后,都出现了一个 hidden cell 的冗余配置:

iOS 14 中屏幕上的所有 cell 走完 enqueue\dequeue\configure 流程,所以 cell 与的 indexPath 对应关系在刷新前后发生了较大的变化;

iOS 15 在同样的调用下,会计算 diff 实现数据刷新,移除最后一个 cell(0x12ce4ed90),而不再做额外的工作。但出现了一个 hidden cell 配置了许多次。

调用 reconfigure 也有类似的现象。折腾并研究半天之后,将此问题 post 在到论坛上,等了一天终于等到了 Apple 工程师的耐心解答:

Please give it a try on iOS 15 beta 2, there are new optimizations in beta 2 (which were not in beta 1) that will reduce or eliminate the number of extra cells requested when you use apply(_:animatingDifferences:). In some cases, you may still see a few extra cells requested, but this will usually only happen the first time you apply a snapshot. The reason that extra cells can be requested sometimes is because UICollectionView needs to perform self-sizing of some cells near the visible region in order to resolve estimated sizes and accurately determine which cells need to be visible, so in certain cases it will ask for cells that may not immediately become visible. However, in iOS 15 any extra cells requested for self-sizing will be kept cached by UICollectionView as prepared cells (similar to the way cells get prefetched), so that they can be immediately made visible when you scroll to them.

— Frameworks Engineer  5 hours ago

结论:如题。

EOF

— Jun 28, 2021