Skip to content

Commit 5330ecf

Browse files
committed
updated
1 parent bf3030f commit 5330ecf

File tree

5 files changed

+95
-80
lines changed

5 files changed

+95
-80
lines changed

Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/AdvancedCollectionTableView/DiffableDataSource/NSCollectionView/CollectionViewDiffableDataSource+Delegate.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,15 @@ extension CollectionViewDiffableDataSource {
165165

166166
func validateDropInto(_ draggingInfo: NSDraggingInfo, _ proposedIndexPath: IndexPath) -> NSDragOperation {
167167
guard dataSource.droppingHandlers.isDroppableInto, let handler = dataSource.droppingHandlers.canDropInto, let element = dataSource.element(for: proposedIndexPath) else { return [] }
168-
let content = draggingInfo.draggingPasteboard.content
169-
dropIntoElement = !content.isEmpty && handler(content, element) ? element : nil
168+
dropIntoElement = handler(draggingInfo.dropInfo(for: dataSource.collectionView), element) ? element : nil
170169
return dropIntoElement != nil ? .copy : []
171170
}
172171

173172
func validateDrop(_ draggingInfo: NSDraggingInfo) -> NSDragOperation {
174173
guard let canDrop = dataSource.droppingHandlers.canDrop, let elementsHandler = dataSource.droppingHandlers.elements else { return [] }
175-
let content = draggingInfo.draggingPasteboard.content
176-
if !content.isEmpty && canDrop(content) {
177-
droppingElements = elementsHandler(content)
174+
let dropInfo = draggingInfo.dropInfo(for: dataSource.collectionView)
175+
if canDrop(dropInfo) {
176+
droppingElements = elementsHandler(dropInfo)
178177
}
179178
return !droppingElements.isEmpty ? .copy : []
180179
}
@@ -238,6 +237,7 @@ extension CollectionViewDiffableDataSource {
238237
}
239238

240239
func collectionView(_ collectionView: NSCollectionView, acceptDrop draggingInfo: NSDraggingInfo, indexPath: IndexPath, dropOperation: NSCollectionView.DropOperation) -> Bool {
240+
let dropInfo = draggingInfo.dropInfo(for: dataSource.collectionView)
241241
if draggingInfo.draggingSource as? NSCollectionView === collectionView {
242242
guard !draggingElements.isEmpty else { return false }
243243
if dropOperation == .before {
@@ -252,16 +252,14 @@ extension CollectionViewDiffableDataSource {
252252
return false
253253
}
254254
} else if dropOperation == .on, let element = dropIntoElement {
255-
let content = draggingInfo.draggingPasteboard.content
256-
dataSource.droppingHandlers.didDropInto?(content, element)
255+
dataSource.droppingHandlers.didDropInto?(dropInfo, element)
257256
return true
258257
} else if dropOperation == .before, !droppingElements.isEmpty {
259-
let content = draggingInfo.draggingPasteboard.content
260258
let transaction: DiffableDataSourceTransaction<Section, Element> = dataSource.dropTransaction(droppingElements, indexPath: indexPath)
261-
dataSource.droppingHandlers.willDrop?(content, droppingElements, transaction)
259+
dataSource.droppingHandlers.willDrop?(dropInfo, droppingElements, transaction)
262260
dataSource.apply(transaction.finalSnapshot, dataSource.droppingHandlers.animates ? .animated : .withoutAnimation)
263261
dataSource.selectElements(droppingElements, scrollPosition: [])
264-
dataSource.droppingHandlers.didDrop?(content, droppingElements, transaction)
262+
dataSource.droppingHandlers.didDrop?(dropInfo, droppingElements, transaction)
265263
return true
266264
}
267265
return false

Sources/AdvancedCollectionTableView/DiffableDataSource/NSCollectionView/CollectionViewDiffableDataSource.swift

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -994,41 +994,40 @@ open class CollectionViewDiffableDataSource<Section: Identifiable & Hashable, El
994994

995995
/// Handlers for dragging pasteboard items inside the collection view.
996996
public struct DroppingHandlers {
997-
public var canDropInto: ((_ content: [PasteboardReading], _ element: Element) -> (Bool))?
998-
public var didDropInto: ((_ content: [PasteboardReading], _ element: Element)->())?
997+
/// The handler that determines whether the proposed drop can be dropped to an element.
998+
public var canDropInto: ((_ dropInfo: DropInfo, _ element: Element) -> Bool)?
999+
/// The handler that gets called when pasteboard content is dropped to an element.
1000+
public var didDropInto: ((_ dropInfo: DropInfo, _ element: Element)->())?
9991001
var isDroppableInto: Bool {
10001002
canDropInto != nil && didDropInto != nil
10011003
}
1002-
10031004

10041005
/**
1005-
The handler that determines the elements to be inserted for the dropping pasteboard content.
1006+
The handler that determines whether the pasteboard content can be dropped to the collection view.
10061007

1007-
- Parameters:
1008-
- content: The content of the dropping pasteboard.
1009-
- target: The target element of the drop.
1008+
- Parameter dropInfo: The information about the proposed drop.
10101009
*/
1011-
public var canDrop: ((_ content: [PasteboardReading]) -> (Bool))?
1010+
public var canDrop: ((_ dropInfo: DropInfo) -> Bool)?
10121011
/**
10131012
The handler that gets called when pasteboard content is about to drop inside the collection view.
10141013

10151014
- Parameters:
1016-
- content: The content of the dropping pasteboard.
1017-
- target: The target element of the drop.
1018-
- transaction: The transaction for the drop, if new elements are provided via ``elements``.
1015+
- dropInfo: The information about the drop.
1016+
- newElements: The new elements to be inserted for the drop.
1017+
- transaction: The transaction for the drop.
10191018
*/
1020-
public var willDrop: ((_ content: [PasteboardReading], _ newElements: [Element], _ transaction: DiffableDataSourceTransaction<Section, Element>) -> ())?
1019+
public var willDrop: ((_ dropInfo: DropInfo, _ newElements: [Element], _ transaction: DiffableDataSourceTransaction<Section, Element>) -> ())?
10211020
/**
10221021
The handler that gets called when pasteboard content was dropped inside the collection view.
10231022

10241023
- Parameters:
1025-
- content: The content of the pasteboard.
1026-
- target: The target element of the drop.
1027-
- transaction: The transaction for the drop, if new elements are provided via ``elements``.
1024+
- dropInfo: The information about the drop.
1025+
- newElements: The new elements that have be inserted for the drop.
1026+
- transaction: The transaction for the drop.
10281027
*/
1029-
public var didDrop: ((_ content: [PasteboardReading], _ newElements: [Element], _ transaction: DiffableDataSourceTransaction<Section, Element>) -> ())?
1030-
/// The handler that determinates the elements for the dropping pasteboard content.
1031-
public var elements: ((_ content: [PasteboardReading]) -> ([Element]))?
1028+
public var didDrop: ((_ dropInfo: DropInfo, _ newElements: [Element], _ transaction: DiffableDataSourceTransaction<Section, Element>) -> ())?
1029+
/// The handler that determinates the elements for the proposed drop.
1030+
public var elements: ((_ dropInfo: DropInfo) -> ([Element]))?
10321031
/// A Boolean value that indicates whether dropping elements is animated.
10331032
public var animates: Bool = true
10341033
}

Sources/AdvancedCollectionTableView/DiffableDataSource/NSOutlineView/OutlineViewDiffableDataSource.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,7 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
802802
return reorderingHandlers.canReorder?(draggedItems, item as? ItemIdentifierType) ?? true == true ? .move : []
803803
} else if let canDrop = droppingHandlers.canDrop {
804804
dropItems = []
805-
dropContent = info.draggingPasteboard.content
806-
if canDrop(dropContent, item as? ItemIdentifierType), let items = droppingHandlers.items?(dropContent, item as? ItemIdentifierType), !items.isEmpty {
805+
if canDrop(info.dropInfo(for: outlineView), item as? ItemIdentifierType), let items = droppingHandlers.items?(info.dropInfo(for: outlineView), item as? ItemIdentifierType), !items.isEmpty {
807806
dropItems = items
808807
return .move
809808
}
@@ -835,9 +834,9 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
835834
var snapshot = snapshot()
836835
snapshot.insert(dropItems, atIndex: index, of: item as? ItemIdentifierType)
837836
let transaction = OutlineViewDiffableDataSourceTransaction<ItemIdentifierType>.init(initial: currentSnapshot, final: snapshot)
838-
droppingHandlers.willDrop?(dropContent, item as? ItemIdentifierType, dropItems, transaction)
837+
droppingHandlers.willDrop?(info.dropInfo(for: outlineView), item as? ItemIdentifierType, dropItems, transaction)
839838
apply(snapshot, droppingHandlers.animates ? .animated : .withoutAnimation)
840-
droppingHandlers.didDrop?(dropContent, item as? ItemIdentifierType, dropItems, transaction)
839+
droppingHandlers.didDrop?(info.dropInfo(for: outlineView), item as? ItemIdentifierType, dropItems, transaction)
841840
return true
842841
}
843842
return false
@@ -1014,13 +1013,13 @@ public class OutlineViewDiffableDataSource<ItemIdentifierType: Hashable>: NSObje
10141013
/// Handlers for dropping items inside the outline view.
10151014
public struct DroppingHandlers {
10161015
/// The handler that determines whether a drop with the pasteboard content is accepted.
1017-
public var canDrop: ((_ content: [PasteboardReading], _ parent: ItemIdentifierType?) -> (Bool))?
1016+
public var canDrop: ((_ dropInfo: DropInfo, _ parent: ItemIdentifierType?) -> Bool)?
10181017
/// The handler that determinates the items to be inserted for the pasteboard content.
1019-
public var items: ((_ content: [PasteboardReading], _ parent: ItemIdentifierType?) -> ([ItemIdentifierType]))?
1018+
public var items: ((_ dropInfo: DropInfo, _ parent: ItemIdentifierType?) -> ([ItemIdentifierType]))?
10201019
/// The handler that gets called before new items are dropped.
1021-
public var willDrop: ((_ content: [PasteboardReading], _ parent: ItemIdentifierType?, _ newItems: [ItemIdentifierType], _ transaction: OutlineViewDiffableDataSourceTransaction<ItemIdentifierType>) -> ())?
1020+
public var willDrop: ((_ dropInfo: DropInfo, _ parent: ItemIdentifierType?, _ newItems: [ItemIdentifierType], _ transaction: OutlineViewDiffableDataSourceTransaction<ItemIdentifierType>) -> ())?
10221021
/// The handler that gets called after new items are dropped.
1023-
public var didDrop: ((_ content: [PasteboardReading], _ parent: ItemIdentifierType?, _ newItems: [ItemIdentifierType], _ transaction: OutlineViewDiffableDataSourceTransaction<ItemIdentifierType>) -> ())?
1022+
public var didDrop: ((_ dropInfo: DropInfo, _ parent: ItemIdentifierType?, _ newItems: [ItemIdentifierType], _ transaction: OutlineViewDiffableDataSourceTransaction<ItemIdentifierType>) -> ())?
10241023
/// A Boolean value that indicates whether dropping items is animated.
10251024
public var animates: Bool = false
10261025
/// A Boolean value that indicates whether the dropped items are previewed.

0 commit comments

Comments
 (0)