yacir/CollectionViewSlantedLayout

Layout attributes were received from the layout but are not valid for the data source counts. Attributes will be ignored.

WestFR opened this issue · 4 comments

Hello,

First of all, apologize for my level of English language.
I have setup a view collection with a search bar and filters. The layout being made with your package.

When i perform a reload on this with this method : self.collectionView.collectionViewLayout.invalidateLayout().

I obtain this error on the debugger :

[CollectionView] Layout attributes <CollectionViewSlantedLayout.CollectionViewSlantedLayoutAttributes: 0x7ff1035113c0> index path: (<NSIndexPath: 0xbcd26c36f94746f0> {length = 2, path = 0 - 3}); frame = (0 603; 414 275); zIndex = 3;  were received from the layout <CollectionViewSlantedLayout.CollectionViewSlantedLayout: 0x7ff1035148a0> but are not valid for the data source counts. Attributes will be ignored.

After research i solved it by adding this method to your class CollectionViewSlantedLayout.swift

The method to add is :

override open func invalidateLayout() {
    super.invalidateLayout()
    self.cachedAttributes.removeAll()
}

I can put this code and make a pull request if you want and if you are ok.

stale commented

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version
  2. Comment that the issue is still reproducible and include:
    • What version of CollectionViewSlantedLayout you reproduced the issue on
    • What steps you followed to reproduce the issue

Issues that are labeled as crash will not be automatically marked as stale.

@yacir If you want up this issue :)

Hi @yacir , thanks for sharing the great feature and its implementation! I also experienced the similar issue that the layout is all messed up when try to reload. I found the issue is due to non-clean-invalidation before recalculation. Amend to what @WestFR suggested, the following would be the solution. Thanks!

override open func invalidateLayout() {
        super.invalidateLayout()
        self.cachedAttributes.removeAll()
        self.cachedContentSize = 0
        self.currentSize = CGSize.zero
}
yacir commented

@WestFR @DreaMorrin Hello guys ! sorry i was busy with other projects. I'll fix it soom