-
Notifications
You must be signed in to change notification settings - Fork 74
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
Fix NSTableView animations #70
Conversation
…dates with empty diff
I don't think we should drop the calls to For example, an item in your shopping cart might change its price. Differ would leave this cell as is when diffing based on the items' IDs, but the cell still needs to redraw and potentially requires more space to do so. |
Thanks for the feedback, good point. For my use case I wanted it to exactly prevent the behaviour because I handled those needed resizes/redraws more specifically. But I understand now that people may rely on it and expect it. Would it be alright to add a parameter defaulting to the always update behaviour like: |
Intuitively, I'd want to avoid a Could you elaborate on what you are currently doing to handle the resizes for specifically? |
I have a UITableView and NSTableView with "self-sizing" cells that involve text editing which loops through a model layer. In order to prevent loss of firstResponder, other potential glitches and for keeping the updates to the minimum necessary, I do the following when a new list of items "arrives": For items which have been in the old list as well and have changed (based on full equality check), and have a visible cell, I update their contentView directly and take note of the potential changed height, on iOS by wrapping in begin/endUpdates and on macOS by calling |
Personally I don't see a reason to use separate Here's how I usually update my table views. Maybe you can give that a try? In your case with dynamic row heights, you'd want to run the block to update the cell's models before calling out to Differ, such that they are configured correctly by the time func transition(to newItems: [Item]) {
// With the cells not being able to listen for changes — they simply
// get a snapshot of an item at one point time — we need to make
// sure that cells which haven't been inserted or deleted are up to
// date.
for indexPath in self.tableView.indexPathsForVisibleRows ?? [] {
if let cell = self.tableView.cellForRow(at: indexPath) as? YourCellType {
let newItem = newItems[indexPath.row]
if self.items.containsDifferentSnapshot(of: newItem) {
cell.item = newItem
}
}
}
// We diff based on _record identities_ here
self.tableView.animateRowChanges(
oldData: self.items,
newData: newItems,
isEqual: { $0.id == $1.id },
updateData: { self.items = newItems } // See #62, coming soon™
)
} extension Collection where Element: Equatable & Identifiable {
public func containsDifferentSnapshot(of element: Element) -> Bool {
return contains(where: { $0.id == element.id && $0 != element })
}
} Please let me know if this works for you. |
I do a similar approach in my project, but can't go into more detail now. |
…es/endUpdates with empty diff" This reverts commit 1c08885.
…STableView - leave this case to caller
@tonyarnold fyi this is a the new PR after discarding #69 |
- Remove CustomEquatable in favor of diff.patch - re-add deprecated indexPathTransform variants - add lost default argument for deprecated diff apply method - add // MARKS
@jenox please have a look at the new code. By the way, I - and probably users who's compilation won't break :) - appreciate you taking the time to look at this in such detail! |
@hannesoid Looks good in my opinion now! I can't merge things here though, @tonyarnold will need to do that. |
I'm going to merge this into |
thanks @tonyarnold! |
NSTableView
UITableView
prevent beginUpdates/endUpdates for empty diffremoved after discussion