Skip to content

Conversation

rmarinho
Copy link
Member

@rmarinho rmarinho commented Jan 19, 2024

Description of Change

When we have Items with different width or height users should use MeasureAllItems for that we rely on AutoLayout of CollectionView . This works by setting the EstimatedItemSize to some value other then empty.
We use the 1st cell as the prototype to be measured and use as EstimatedItemSize, but the problem that we see here, is that cell size is the smalles compared with the other cells that haver a wider width. When CollectionView is calculating the ContentSize, it use the EstimatedItemSize and multiplies by the number of items of the section. IF the EstimatedItemSize is very small the ContentSize can hide items in the end of the collection. This is special an issue if we have a couple of items on the List.

I can't reproduce this on VerticalList so I m not sure if this is or not a issue with how UICollectionView and EstimatedItemSize. Because the idea is even if we give it a "estimated size" if should call each item to get the real value (and it does) but to does not update the initial calculate ContentSize We have seen other issues with horizontal scroll on UICollectionView so im not sure if this is also a bug related with that or not.

The fix here is simple, try to find the wider cell from the ones that are going to maybe be visible on the screen. That way the EstimatedItemSize will return a value that will fit all the cells.

Still need to write a test.

Issues Fixed

Fixes #15815

@rmarinho rmarinho added platform/ios area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Jan 19, 2024
@rmarinho rmarinho marked this pull request as ready for review January 26, 2024 12:50
@rmarinho rmarinho requested a review from a team as a code owner January 26, 2024 12:50
@rmarinho rmarinho requested review from Redth and removed request for StephaneDelcroix February 7, 2024 16:31
@tj-devel709
Copy link
Member

So for my understanding, without your changes, the layout you created for your uitest doesn't work because the layout reserved three 50-width spots and the second item takes up both of them?
image

@rmarinho
Copy link
Member Author

yes @tj-devel709 that's it, when we have just a couple of items, the estimated size (1st item) is smaller than other cells that will be visible it will take that space.

Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking OK. I have some questions because my iOS CollectionView knowledge is weak. Also, I am wondering if the test really does catch this type of case.

@PureWeen
Copy link
Member

/rebase

Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to cover aspects such as grouping, etc. but I see that we have another open issue for this.

@rmarinho rmarinho merged commit ffc20bf into main Feb 19, 2024
@rmarinho rmarinho deleted the fix-15815 branch February 19, 2024 14:19
rmarinho added a commit that referenced this pull request Feb 22, 2024
* [Samples] Add repro case for issue #15815

* [iOS] Remove dead code

* [iOS] Try find a better EstimatedItemSize for horizontal list

* [uitest] Add Uitest for CollectionView

* Fix test

* Pink color
rmarinho added a commit that referenced this pull request Feb 27, 2024
* [Samples] Add repro case for issue #15815

* [iOS] Remove dead code

* [iOS] Try find a better EstimatedItemSize for horizontal list

* [uitest] Add Uitest for CollectionView

* Fix test

* Pink color
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS: CollectionView - Horizontal CollectionView does not show the last element under some conditions
6 participants