WICG / virtual-scroller

Other
2k stars 83 forks source link

Specify range of items in visible rect for animation #132

Open KevinDoughty opened 6 years ago

KevinDoughty commented 6 years ago

To animate items along the scroll axis, while scrolling, there is a need to specify a range of present items other than merely those that intersect the visible rect. I am a proponent of the data source pattern, but I know of no implementations sufficient for this, and I hope you will consider adding this feature. In my own javascript implementation I created a data source method, rangeOfItemsInRect. UITableView fails in this regard, as you can see in this video with exaggerated timing to show the effect:

https://www.youtube.com/watch?v=C1p9qEuMNns

This is not the only use, however. Animating reflow of a grid layout when resizing the viewport from wide to narrow would instantly change the non-animated visible range, which would need to be expanded to include items still animating, much like in the video from this comment:

https://github.com/valdrinkoshi/virtual-scroller/issues/64#issuecomment-418199598

rakina commented 5 years ago

The new approach for virtual-scroller (detailed in the newly-updated explainer) actually puts all of the content in the DOM now. IIUC, that means this issue should be solved by the new approach already - do you think so?

KevinDoughty commented 5 years ago

I have not looked at virtual-scroller in awhile. I am interested in animating lists and grids and my demands are high. Unfortunately, the getters rangeFirst and rangeLast are not quite sufficient. If you and only you control what range of items are rendered, perhaps by viewport intersection, I will not be able to animate other items outside of that range during scrolling or resize. They would be visible because of animation, but only if I could get virtual-scroller to render them.

rakina commented 5 years ago

Oh, interesting. It might be useful to add a way to say "this child needs to be rendered regardless of its position relative to the viewport". Do you think that would help?

KevinDoughty commented 5 years ago

Yes! That sounds about right.

KevinDoughty commented 5 years ago

Here are more examples of animations on scrolling and resize that would break without this feature.

Scrolling of NSTextView and custom grid view in AppKit: https://twitter.com/KvnDy/status/884525547312877568

Resize of my own windowing/virtual collection view written in javascript. Without this feature, items would instantly disappear when resizing from wide to narrow, right to left: https://twitter.com/KvnDy/status/775872332028141568

This also shows resize, but highlights why I think your solution for https://github.com/WICG/virtual-scroller/issues/64 will not be sufficient for grid animation. I will file an issue if I determine this to be the case. https://twitter.com/KvnDy/status/775142451916988416