Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public extension CollectionDataAnimationDelegate {
return .preciseAnimations
}

func animateAlongsideUpdate(with duration: TimeInterval) { }
func animateAlongsideUpdate(for state: CollectionDataAnimationState) { }
}

public extension CollectionSectionDataAnimationDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ extension UITableView: DeltaUpdatableView {

public func reloadSections(for sectionUpdates: [SectionUpdate]) {

performBatchUpdates({ [weak self] in
performBatchUpdates(.reload, delegates: sectionUpdates.uniqueAnimationDelegates, { [weak self] in
sectionUpdates.forEach { sectionUpdate in
sectionUpdate.update()
guard self != nil else { return }
guard let self else { return }
let indexSet = IndexSet([sectionUpdate.section])
reloadSections(indexSet, with: preferredReloadSectionAnimation(for: sectionUpdate.section))
self.reloadSections(indexSet, with: self.preferredReloadSectionAnimation(for: sectionUpdate.section))
}
sectionUpdates.uniqueAnimationDelegates.forEach { $0.animateAlongsideUpdate(with: TimeInterval.standardCollectionAnimationDuration) }
}, completion: { _ in
sectionUpdates.forEach { $0.completion?() }
})
Expand Down Expand Up @@ -202,11 +201,10 @@ extension UICollectionView: DeltaUpdatableView {
let sections = sectionUpdates.map { $0.section }
let indexSet = IndexSet(sections)

performBatchUpdates({ [weak self] in
performBatchUpdates(.reload, delegates: sectionUpdates.uniqueAnimationDelegates, { [weak self] in
sectionUpdates.forEach { $0.update() }
guard self != nil else { return }
reloadSections(indexSet)
sectionUpdates.uniqueAnimationDelegates.forEach { $0.animateAlongsideUpdate(with: TimeInterval.standardCollectionAnimationDuration) }
guard let self else { return }
self.reloadSections(indexSet)
}, completion: { _ in
sectionUpdates.forEach { $0.completion?() }
})
Expand Down Expand Up @@ -464,13 +462,13 @@ private extension Sequence where Element == SectionUpdate {

// MARK: AnimationDelegate Helper

private extension UITableView {
extension UITableView {

func performBatchUpdates(_ group: CollectionDataAnimationGroup, delegates: [CollectionDataAnimationDelegate], _ updates: (() -> Void)?, completion: ((Bool) -> Void)? = nil) {
func performBatchUpdates(_ group: CollectionDataAnimationGroup, delegates: [CollectionDataAnimationDelegate], _ updates: () -> Void, completion: ((Bool) -> Void)? = nil) {
delegates.forEach { $0.animateAlongsideUpdate(for: .immediatelyBefore(group: group, duration: TimeInterval.standardCollectionAnimationDuration)) }

performBatchUpdates {
updates?()
updates()
delegates.forEach { $0.animateAlongsideUpdate(for: .during(group: group, duration: TimeInterval.standardCollectionAnimationDuration)) }
} completion: { value in
completion?(value)
Expand All @@ -481,13 +479,13 @@ private extension UITableView {
}
}

private extension UICollectionView {
extension UICollectionView {

func performBatchUpdates(_ group: CollectionDataAnimationGroup, delegates: [CollectionDataAnimationDelegate], _ updates: (() -> Void)?, completion: ((Bool) -> Void)? = nil) {
func performBatchUpdates(_ group: CollectionDataAnimationGroup, delegates: [CollectionDataAnimationDelegate], _ updates: () -> Void, completion: ((Bool) -> Void)? = nil) {
delegates.forEach { $0.animateAlongsideUpdate(for: .immediatelyBefore(group: group, duration: TimeInterval.standardCollectionAnimationDuration)) }

performBatchUpdates {
updates?()
updates()
delegates.forEach { $0.animateAlongsideUpdate(for: .during(group: group, duration: TimeInterval.standardCollectionAnimationDuration)) }
} completion: { value in
completion?(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,20 @@ extension UITableView: SectionDeltaUpdatableView {
self.reloadRows(at: automaticReloadIndexPaths, with: self.preferredReloadRowAnimation)
}

performBatchUpdates({ [weak self] in
performBatchUpdates(.insertDeleteMove, delegates: delegate.flatMap { [$0 as CollectionDataAnimationDelegate] } ?? [], { [weak self] in
updateData()
guard let strongSelf = self else { return }
guard strongSelf.isVisibleOnScreen else {
strongSelf.reloadData()
return
}
deleteMoveInsert()
delegate?.animateAlongsideUpdate(with: TimeInterval.standardCollectionAnimationDuration)
}, completion: { [weak self] _ in
guard let strongSelf = self else {
completion?()
return
}
strongSelf.performBatchUpdates({ [weak weakSelf = strongSelf] in
strongSelf.performBatchUpdates(.reload, delegates: delegate.flatMap { [$0 as CollectionDataAnimationDelegate] } ?? [], { [weak weakSelf = strongSelf] in
guard let strongSelf = weakSelf else { return }
guard strongSelf.isVisibleOnScreen else {
strongSelf.reloadData()
Expand Down Expand Up @@ -238,7 +237,7 @@ extension UICollectionView: SectionDeltaUpdatableView {
}
}

performBatchUpdates({ [weak self] in
performBatchUpdates(.insertDeleteMove, delegates: delegate.flatMap { [$0 as CollectionDataAnimationDelegate] } ?? [], { [weak self] in
updateData()
guard let strongSelf = self else { return }
guard strongSelf.isVisibleOnScreen else {
Expand All @@ -250,13 +249,12 @@ extension UICollectionView: SectionDeltaUpdatableView {
strongSelf.moveItem(at: indexPathPair.source as IndexPath, to: indexPathPair.target as IndexPath)
}
strongSelf.insertItems(at: itemIndexPathDelta.insertions as [IndexPath])
delegate?.animateAlongsideUpdate(with: TimeInterval.standardCollectionAnimationDuration)
}, completion: { [weak self] _ in
guard let strongSelf = self else {
completion?()
return
}
strongSelf.performBatchUpdates({ [weak weakSelf = strongSelf] in
strongSelf.performBatchUpdates(.reload, delegates: delegate.flatMap { [$0 as CollectionDataAnimationDelegate] } ?? [], { [weak weakSelf = strongSelf] in
guard let strongSelf = weakSelf else { return }
guard strongSelf.isVisibleOnScreen else {
strongSelf.reloadData()
Expand Down