Skip to content

Commit 7d97a81

Browse files
committed
updated
1 parent 5cd7bfa commit 7d97a81

File tree

2 files changed

+114
-6
lines changed

2 files changed

+114
-6
lines changed

Example/Example/MainViewController.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import AppKit
99
import AdvancedCollectionTableView
10+
import FZSwiftUtils
11+
import FZUIKit
1012

1113
class MainViewController: NSViewController {
1214
typealias DataSource = CollectionViewDiffableDataSource<Section, GalleryItem>
@@ -47,9 +49,56 @@ class MainViewController: NSViewController {
4749
}
4850
}
4951

52+
let testView = TestView()
53+
let view1 = TestView()
54+
let view2 = TestView()
5055
override func viewDidLoad() {
5156
super.viewDidLoad()
5257

58+
59+
Swift.print("view1", view1.tag)
60+
Swift.print("view2", view2.tag)
61+
62+
Swift.print("-----")
63+
testView.addSubview(view1)
64+
Swift.print("-----")
65+
testView.addSubview(view2)
66+
Swift.print("-----")
67+
testView.addSubview(view1)
68+
Swift.print("-----")
69+
testView.subviews = [view1, view2]
70+
Swift.print("-----")
71+
testView.subviews = [view2, view1]
72+
Swift.print("-----")
73+
testView.subviews = [view2]
74+
75+
76+
var configuration = NSListContentConfiguration.sidebar()
77+
configuration.text = LoremIpsum.words(3)
78+
configuration.secondaryText = LoremIpsum.words(6)
79+
configuration.secondaryTextProperties.maximumNumberOfLines = 0
80+
configuration.image = NSImage(systemSymbolName: "photo")
81+
let contentView = configuration.makeContentView()
82+
contentView.frame.size = contentView.systemLayoutSizeFitting(width: 400)
83+
let containerView = NSTableCellView()
84+
containerView.frame.origin = CGPoint(20)
85+
containerView.frame.size = contentView.frame.size
86+
87+
containerView.addSubview(contentView)
88+
containerView.cornerRadius = contentView.frame.size.height / 2.0
89+
Swift.print(contentView.frame.size.height / 2.0)
90+
contentView.frame.origin.x = contentView.frame.size.height / 2.0
91+
containerView.backgroundColor = .controlAccentColor
92+
containerView.backgroundStyle = .emphasized
93+
// view.addSubview(containerView)
94+
95+
let maskView = MaskView().size(CGSize(120, 60))
96+
maskView.backgroundColor = .clear
97+
maskView.shadowPath = .init(rect: maskView.bounds)
98+
view.addSubview(maskView)
99+
// maskView.configurate(using: ShapeConfiguration.capsule)
100+
maskView.outerShadow = .accentColor(opacity: 0.9)
101+
53102
collectionView.collectionViewLayout = .grid(columns: 3)
54103
collectionView.dataSource = dataSource
55104

@@ -87,6 +136,28 @@ class MainViewController: NSViewController {
87136
}
88137
}
89138

139+
class MaskView: NSView {
140+
let shapeLayer = CAShapeLayer()
141+
142+
override func layout() {
143+
super.layout()
144+
145+
shapeLayer.frame = bounds
146+
shapeLayer.path = NSBezierPath(roundedRect: bounds, cornerRadius: bounds.height/2.0).cgPath
147+
}
148+
149+
override init(frame frameRect: NSRect) {
150+
super.init(frame: frameRect)
151+
wantsLayer = true
152+
// layer?.addSublayer(shapeLayer)
153+
shapeLayer.fillColor = NSColor.controlAccentColor.cgColor
154+
}
155+
156+
required init?(coder: NSCoder) {
157+
super.init(coder: coder)
158+
}
159+
}
160+
90161
private extension NSView {
91162
/// Creates a colored view.
92163
convenience init(color: NSColor, opacity: CGFloat) {
@@ -95,3 +166,40 @@ private extension NSView {
95166
alphaValue = opacity
96167
}
97168
}
169+
170+
171+
172+
class TestView: NSView {
173+
var _tag: Int = Int.random(max: 30)
174+
175+
override var tag: Int {
176+
_tag
177+
}
178+
179+
override func layout() {
180+
super.layout()
181+
Swift.print("layout")
182+
}
183+
184+
override func viewDidMoveToSuperview() {
185+
Swift.print("superview viewDidMoveToSuperview", superview != nil)
186+
}
187+
188+
override func viewWillMove(toSuperview newSuperview: NSView?) {
189+
Swift.print("superview viewWillMove", newSuperview != nil)
190+
}
191+
192+
override func layoutSubtreeIfNeeded() {
193+
Swift.print("layoutSubtreeIfNeeded")
194+
}
195+
196+
override func willRemoveSubview(_ subview: NSView) {
197+
Swift.print("willRemoveSubview", subview.tag)
198+
199+
}
200+
201+
override func didAddSubview(_ subview: NSView) {
202+
Swift.print("didAddSubview", subview.tag)
203+
}
204+
}
205+

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/OutlineViewDiffableDataSource.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
5151
var draggedItems: [ItemIdentifierType] = []
5252
var draggedParent: ItemIdentifierType?
5353
var draggedIndexes: [Int] = []
54-
var canDrop: NSDragOperation = []
54+
var canDrop = false
5555
var isApplyingSnapshot = false
5656
var didApplyGroupItems = false
5757
lazy var groupRowTableColumn = NSTableColumn()
@@ -843,7 +843,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
843843
*/
844844

845845
public func outlineView(_ outlineView: NSOutlineView, validateDrop info: any NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation {
846-
canDrop = []
846+
canDrop = false
847847
if info.draggingSource as? NSOutlineView === outlineView {
848848
if let item = item as? ItemIdentifierType, draggedItems.contains(item) {
849849
return []
@@ -867,7 +867,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
867867
if info.draggingSource as? NSTableView !== outlineView {
868868
if let canDrag = droppingHandlers.canDrop {
869869
self.canDrop = canDrag(info.dropInfo(for: outlineView), item as? ItemIdentifierType)
870-
return self.canDrop
870+
return self.canDrop ? .copy : []
871871
}
872872
}
873873
return []
@@ -894,7 +894,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
894894
reorderingHandlers.didReorder?(transaction)
895895
return true
896896
}
897-
if info.draggingSource as? NSOutlineView !== outlineView, canDrop != [] {
897+
if info.draggingSource as? NSOutlineView !== outlineView, canDrop {
898898
let dropInfo = info.dropInfo(for: outlineView)
899899
let item = item as? ItemIdentifierType
900900
let items = droppingHandlers.items?(dropInfo) ?? []
@@ -915,7 +915,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
915915
}
916916

917917
public func outlineView(_ outlineView: NSOutlineView, updateDraggingItemsForDrag draggingInfo: any NSDraggingInfo) {
918-
if canDrop != [], droppingHandlers.previewDroppedItems, let items = droppingHandlers.items?(draggingInfo.dropInfo(for: outlineView)), !items.isEmpty, let image = previewImage(for: items) {
918+
if canDrop, droppingHandlers.previewDroppedItems, let items = droppingHandlers.items?(draggingInfo.dropInfo(for: outlineView)), !items.isEmpty, let image = previewImage(for: items) {
919919
draggingInfo.setDraggedImage(image)
920920
}
921921
}
@@ -1086,7 +1086,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
10861086
/// Handlers for dropping items inside the outline view.
10871087
public struct DroppingHandlers {
10881088
/// The handler that determines whether a drop with the pasteboard content is accepted.
1089-
public var canDrop: ((_ dropInfo: DropInfo, _ target: ItemIdentifierType?) -> NSDragOperation)?
1089+
public var canDrop: ((_ dropInfo: DropInfo, _ target: ItemIdentifierType?) -> Bool)?
10901090

10911091
/// The handler that determinates the items to be inserted for the pasteboard content.
10921092
public var items: ((_ dropInfo: DropInfo) -> ([ItemIdentifierType]))?

0 commit comments

Comments
 (0)