Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section removals cause wrong calls to CollectionCellElement's didDisappear #16

Open
JosephDuffy opened this issue Dec 18, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@JosephDuffy
Copy link
Member

JosephDuffy commented Dec 18, 2020

Describe the bug

When a section is deleted the didDisappear call on CollectionElementsProvider is either not made or is made on the wrong CollectionElementsProvider.

To Reproduce

Delete a section.

Expected behavior

Correct calls to didDisappear should be made/should not crash.

Environment

  • OS Version: Any iOS
  • Library Version: 1.05
  • Device: Any

Additional context

CollectionCoordinator.collectionView(_:didEndDisplaying:forItemAt:) uses the state of the hierarchy after the more recent updates have been applied, meaning the removed cell/section is no longer in the SectionProviderMapping or the local cachedProviders.

For example deleting section 1 with a hierarchy of:

  • section 0
    • 0-0
    • 0-1
    • 0-2
  • section 1
    • 1-0
    • 1-1
  • section 2

Then remove section 1:

  • Crashes when the cell is cast to the wrong type
    • This happens when section 1 and have different cell types
  • Calls the wrong CollectionElementsProvider
    • This happens when section 1 and have the same cell types
    • This would call didDisappear on section 2 (even though no cells were removed and it's already empty)

Or when section 2 is removed:

  • Makes no call at all
    • This happens because of guard indexPath.section < sectionProvider.numberOfSections else { return }

I don't have time to look at this right now and I'm not as familiar with the SectionProviderMapping as other parts, can you try and fix this @shaps80?

A suggested solution is to cache the cells and their sections (e.g. cellSectionMap: [UICollectionViewCell: Section]) but I'd like to know if there's a alternative approach since that might lead to more issues down the line?

@JosephDuffy JosephDuffy added the bug Something isn't working label Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant