TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.3k forks source link

[RTL/Batching] Make ASDisplayShouldFetchBatchForScrollView aware of flipped CV layouts #1985

Closed rcancro closed 3 years ago

rcancro commented 3 years ago

UICollectionViewLayout has a property called flipsHorizontallyInOppositeLayoutDirection. If this is set to YES then a RTL collectionView’s contentOffset behaves like it does in LTR. In other words, the first item is at contentOffset 0. In this case, the existing logic for ASDisplayShouldFetchBatchForScrollView works in RTL.

If you don’t override flipsHorizontallyInOppositeLayoutDirection to be YES, then it means that in RTL languages the first item in your collectionView will actually be at x offset collectionView.contentSize.width - collectionView.frame.size.width. As you scroll to the right, the content offset will decrease until you reach the end of the data at a content offset of 0,0. In this case, ASDisplayShouldFetchBatchForScrollView needs to know that you are in RTL and the layout is not flipped. It can then use the contentOffset as the remainingDistance to determine when to fetch.