-
Notifications
You must be signed in to change notification settings - Fork 12
Fixes, enhancements and back porting to macOS 10.11 #3
base: master
Are you sure you want to change the base?
Conversation
Removed Grouped outline item and moved it to demo instead. Replaced with a subclass. Simplified code to use OutlineViewItem as a concrete type Improvements to demo. Only nodes with children show an expansion indicator. More documentation WIP - Need to fix drag and drop
Reload parent item (old and new) after a move as expansion states don't otherwise refresh
…ving items would otherwise remain broken. Reload parent items when removing / inserting
…g "CollectionDifference" related methods Renamed collection difference methods to avoid clashes on macOS 10.15+
…h deletes child items too Documentation and cleanup Perform reloadData() instead of animating if changes above a certain threshold New test to confirm moving items with children Fixed NSOutlineView glitch where expansion arrow would overlap the label after a remove + insert
Renamed some variables for clarity Renamed IndexedID to IndexedNode Added itemID to Node for consistency
shpakovski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. I’m happy to see new ideas. However this looks like a new component. Not sure 100% how to handle such a massive branch…
But I’m not going to merge it right now, sorry. Instead I’d like to ask you to maintain your public version and make another request for the README with a URL of your implementation.
Thanks for understanding 🙏
| let viewController = NSTabViewController() | ||
| viewController.tabStyle = .unspecified | ||
| viewController.transitionOptions = [] | ||
| viewController.view.wantsLayer = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this change?
| Parent 3 / Child 31 | ||
| Parent 3 / Child 32 | ||
| Parent 3 / Child 33 | ||
| Cars / Toyota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 👍
| var snapshot: DiffableDataSourceSnapshot = .init() | ||
| snapshot.fillItem(nil, with: textView.string) | ||
| snapshotBinding.wrappedValue = snapshot | ||
| snapshotBinding.wrappedValue = snapshot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the whitespace leftover.
|
|
||
| /// Necessary for sets. | ||
| public override var hash: Int { title.hash } | ||
|
|
||
| /// Necessary for outline view reloading. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why this isn’t necessary anymore?
| override var hash: Int { title.hash } | ||
|
|
||
| /// Necessary for outline view reloading. | ||
| override func isEqual(_ object: Any?) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
| if parentItemToAppendTo != nil && appendToParentNode == nil { | ||
| #if DEBUG | ||
| print("insertItems - Cannot find parent item \(String(describing: parentItemToAppendTo))") | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Care to remove spacing in the beginning? 😊
| if targetItem != nil && targetItemNode == nil { | ||
| #if DEBUG | ||
| print("Cannot find item \(String(describing: targetItem))") | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
| public func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool { | ||
| guard let item = item as? OutlineViewItem else { return true } | ||
| return item.isExpandable | ||
| return item.isExpandable && currentSnapshot.childrenOfItem(item).count > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not work after reloading. I introduced isExpandable and count > 0 explicitly to permit the disclosure indicator without children.
|
|
||
| public extension OutlineViewDiffableDataSource { | ||
|
|
||
| /// Returns current state of the data source. This property is thread-safe. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙂
| } | ||
| // When a data source is not set, reload the first time | ||
| guard animatingDifferences, let _ = outlineView?.dataSource else { | ||
| reloadData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this effective enough?
This PR includes a number of enhancements, fixes and a back-port of the diffing algorithm (taken from the open source Swift implementation) so that the module itself can be used on macOS 10.11.
I've also fixed a number of bugs present within the demo with some additional optimizations / tests. Duplicate code has been removed from a few places, plus the code is now easier to follow.
Along the way I've also fixed a few known glitches within NSOutlineView (such as parent nodes appearing with overlapping glyphs).
The PR also includes more documentation and some refactoring.