Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [iOS] Collection view cells with 0 item spacing in a grid layout has gaps, apparently due to rounding #13943

Open
GalaxiaGuy opened this issue Mar 5, 2021 · 3 comments

Comments

@GalaxiaGuy
Copy link
Contributor

Description

A CollectionView using a GridItemsLayout with a Span that is not a whole factor of the collection view's width, and has a HorizontalItemSpacing of 0 will still have a gap.

Steps to Reproduce

  1. Create a CollectionView with a GridItemsLayout with a Span of 3, HoriztonalItemSpacing of 0, and a width that is not a multiple of three (e.g full width of an iPod Touch 7th gen).
  2. Make the CollectionView transparent and give the cells a non-transparent background color.
  3. Make the content behind theCollectionView a different color to the cells.

Expected Behavior

None of the content behind the CollectionView is visible.

Actual Behavior

There is gaps between the cells in which the background content is visible.

Basic Information

  • Version with issue: 5.0.0.2012

Screenshots

Simulator Screen Shot - iPod touch (7th generation) - 2021-03-05 at 12 34 18

Reproduction Link

https://github.com/GalaxiaGuy/xf-bugs/tree/bug/grid-spacing-gap

@GalaxiaGuy GalaxiaGuy added s/unverified New report that has yet to be verified t/bug 🐛 labels Mar 5, 2021
@PureWeen PureWeen added a/collectionview p/iOS 🍎 e/4 🕓 4 and removed s/unverified New report that has yet to be verified labels Mar 5, 2021
@sawankumarbundelkhandi
Copy link

I can confirm it's indeed a bug. For now, I have given HoriztonalItemSpacing as 1

@jtorvald
Copy link
Contributor

I looked into this, and it seems to be a know issue. It's even in the comments of the GridViewLayout (see comment here)

I tried to apply a fix, with rounding and suck but didn't work. It's a tough one to solve I guess. One of the elements needs to be a bit bigger.

A workaround (if the design lets you) can be to give the CollectionView a margin of for example 1 (for example 320 - 2 (both sides 1) divided by 3 is 106 which makes an even number.

@GalaxiaGuy
Copy link
Contributor Author

GalaxiaGuy commented Mar 15, 2021

To a bit a of detail:

I'm porting some functionality already implemented natively in Xamarin.iOS. When I asked the people who implemented the original solution how they dealt with this, they said they just put an opaque box behind the collectionview and adjusted its constraints.

It seems this is just an issue without how UICollectionViewFlowLayout works (i.e., it is designed such that you size the cells and it fits what it can whereas the GridItemLayout assumes you tell it what should fit and it determines the size).

Fixing it completely may require creating a custom UICollectionViewLayout.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants