Skip to content

Commit b52627b

Browse files
committed
Tweak "reanimate" logic
1 parent 95253c0 commit b52627b

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.3.0] - 2019-08-07
4+
5+
### Changed
6+
7+
- Faster typing propagation between master & detail view
8+
39
## [0.2.0] - 2019-08-03
410

511
### Changed

CommonplaceBookApp/DocumentDiffableDataSource.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,21 @@ public final class DocumentDiffableDataSource: UITableViewDiffableDataSource<Doc
9595
cardsPerDocument: cardsPerDocument,
9696
hashtag: filteredHashtag
9797
)
98-
// Only animate inserts & deletes.
99-
// In particular I don't want to animate reloads as I type -- it's too noisy
100-
// I'm said I'm losing reordering animations :-(
101-
// Is there some way, when observing the notebook, to know that it was a typing change?
102-
let reallyAnimate = animated && self.snapshot().numberOfItems != snapshot.numberOfItems
98+
let reallyAnimate = animated && DocumentDiffableDataSource.majorSnapshotDifferences(between: self.snapshot(), and: snapshot)
10399
apply(snapshot, animatingDifferences: reallyAnimate)
104100
}
105101

102+
/// Compares lhs & rhs to see if the differences are worth animating.
103+
private static func majorSnapshotDifferences(between lhs: Snapshot, and rhs: Snapshot) -> Bool {
104+
if lhs.numberOfItems != rhs.numberOfItems {
105+
return true
106+
}
107+
for (lhsItem, rhsItem) in zip(lhs.itemIdentifiers, rhs.itemIdentifiers) {
108+
if lhsItem.pageKey != rhsItem.pageKey { return true }
109+
}
110+
return false
111+
}
112+
106113
private static func snapshot(
107114
for notebook: NoteArchiveDocument,
108115
cardsPerDocument: [String: Int],

0 commit comments

Comments
 (0)