From dc9ca2a2455876092f226a5f620f61ffceb5c6cf Mon Sep 17 00:00:00 2001 From: Christoffer Winterkvist Date: Wed, 24 Apr 2019 21:00:20 +0200 Subject: [PATCH 1/2] Add `animations` flag to `reload` extension on NSCollectionView --- .../macOS/NSCollectionView+Extensions.swift | 20 ++++++++++--------- Source/macOS/NSTableView+Extensions.swift | 14 ++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Source/macOS/NSCollectionView+Extensions.swift b/Source/macOS/NSCollectionView+Extensions.swift index 42e10f9..8a31cca 100644 --- a/Source/macOS/NSCollectionView+Extensions.swift +++ b/Source/macOS/NSCollectionView+Extensions.swift @@ -9,10 +9,11 @@ public extension NSCollectionView { /// - before: A closure that will be invoked before the updates. /// This is where you should update your data source. /// - completion: A closure that is invoked after the updates are done. - public func reload(with changes: [Change], - section: Int = 0, - updateDataSource: (() -> Void), - completion: (() -> Void)? = nil) { + func reload(with changes: [Change], + animations: Bool = false, + section: Int = 0, + updateDataSource: (() -> Void), + completion: (() -> Void)? = nil) { guard !changes.isEmpty else { completion?() return @@ -20,14 +21,15 @@ public extension NSCollectionView { let manager = IndexPathManager() let result = manager.process(changes, section: section) + let object = animations ? animator() : self - animator().performBatchUpdates({ + object.performBatchUpdates({ updateDataSource() - validateUpdates(result.insert, then: animator().insertItems) - validateUpdates(result.updates, then: animator().reloadItems) - validateUpdates(result.deletions, then: animator().deleteItems) + validateUpdates(result.insert, then: object.insertItems) + validateUpdates(result.updates, then: object.reloadItems) + validateUpdates(result.deletions, then: object.deleteItems) if !result.moves.isEmpty { - result.moves.forEach { animator().moveItem(at: $0.from, to: $0.to) } + result.moves.forEach { object.moveItem(at: $0.from, to: $0.to) } } }, completionHandler: nil) diff --git a/Source/macOS/NSTableView+Extensions.swift b/Source/macOS/NSTableView+Extensions.swift index 41b8e57..84bc881 100644 --- a/Source/macOS/NSTableView+Extensions.swift +++ b/Source/macOS/NSTableView+Extensions.swift @@ -10,22 +10,22 @@ public extension NSTableView { /// - before: A closure that will be invoked before the updates. /// This is where you should update your data source. /// - completion: A closure that is invoked after the updates are done. - public func reload(with changes: [Change], - animation: NSTableView.AnimationOptions, - section: Int = 0, - updateDataSource: (() -> Void), - completion: (() -> Void)? = nil) { + func reload(with changes: [Change], + animation: NSTableView.AnimationOptions, + section: Int = 0, + updateDataSource: (() -> Void), + completion: (() -> Void)? = nil) { guard !changes.isEmpty else { completion?() return } - + let manager = IndexPathManager() let result = manager.process(changes, section: section) let insertions = IndexSet(result.insert.compactMap { $0.item }) let deletions = IndexSet(result.deletions.compactMap { $0.item }) let updates = IndexSet(result.updates.compactMap { $0.item }) - + animator().beginUpdates() updateDataSource() validateUpdates(insertions, animation: animation, then: animator().insertRows) From daa859caec74e5e39e2ec0711152c061cf57e2c4 Mon Sep 17 00:00:00 2001 From: Christoffer Winterkvist Date: Wed, 24 Apr 2019 23:16:47 +0200 Subject: [PATCH 2/2] Update Differific.podspec --- Differific.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Differific.podspec b/Differific.podspec index 2256570..a3b5f71 100644 --- a/Differific.podspec +++ b/Differific.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Differific" s.summary = "A fast and convenient diffing framework" - s.version = "0.7.0" + s.version = "0.7.1" s.homepage = "https://github.com/zenangst/Differific" s.license = 'MIT' s.author = { "Christoffer Winterkvist" => "christoffer@winterkvist.com" }