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

Don't animate when dequeuing cells #517

Merged
merged 8 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Copy link
Collaborator Author

@kyleve kyleve Aug 1, 2024

Choose a reason for hiding this comment

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

  • A possible bug I found, should fix before merging: ListView.VisibleContent.update should assign
            self.items = newItems
            self.headerFooters = newHeaderFooters

Before callbacks, otherwise a re-rentrant call could call these twice (or more).

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Fixed

- Fixed an issue where animations would occur when dequeuing / reusing cells. A layout is now forced without animation before presentation.

### Added

### Removed
Expand Down
14 changes: 14 additions & 0 deletions ListableUI/Sources/ListView/ListView.Delegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ extension ListView
item.willDisplay(cell: cell, in: collectionView, for: indexPath)

self.displayedItems[ObjectIdentifier(cell)] = item

UIView.performWithoutAnimation {
/// Force a layout of the cell before it is displayed, so that any implicit animations
/// are avoided. This ensures that cases like toggling a switch on and off are
/// not animated as the cell comes into view.
cell.layoutIfNeeded()
}
}

func collectionView(
Expand Down Expand Up @@ -175,6 +182,13 @@ extension ListView
headerFooter.collectionViewWillDisplay(view: container)

self.displayedSupplementaryItems[ObjectIdentifier(container)] = headerFooter

UIView.performWithoutAnimation {
/// Force a layout of the cell before it is displayed, so that any implicit animations
/// are avoided. This ensures that cases like toggling a switch on and off are
/// not animated as the cell comes into view.
container.layoutIfNeeded()
}
}

func collectionView(
Expand Down
10 changes: 7 additions & 3 deletions ListableUI/Sources/ListView/ListView.VisibleContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ extension ListView
let removed = self.items.subtracting(newItems)
let added = newItems.subtracting(self.items)

// Note: We set these values _before_ we invoke `setAndPerform`,
// incase `setAndPerform` causes an external callback to trigger
// an update, which could cause this method to be re-entrant.

self.items = newItems
self.headerFooters = newHeaderFooters

removed.forEach {
$0.item.setAndPerform(isDisplayed: false)
}

added.forEach {
$0.item.setAndPerform(isDisplayed: true)
}

self.items = newItems
self.headerFooters = newHeaderFooters

// Inform any state reader callbacks of the changes.

Expand Down
Loading