I've written a sample macOS app using SwiftUI, It can import some files by dragging from other apps and export the files by dragging too. However, when I drag the files from the list view of the app and drop it, the app will import the dragging files too as dragging from other apps. I don't know how to detect the dragging from other apps or the dragging from the app itself. Anyone can help? Thanks!
How to detect whether it is self-dragging or not in SwiftUI?
Here is some code snippets:
...
ForEach(pngs) { row in
TableRow(row)
.itemProvider {
row.targetURL.flatMap(NSItemProvider.init(contentsOf:))
}
}
...
.onDrop(of: [.png], isTargeted: $isDropTarget) { providers in
files.removeAll()
providers.forEach { provider in
_ = provider.loadFileRepresentation(for: .png, openInPlace: true) { url, _, _ in
Task { @MainActor in
url.map {
files.append(.init(url: $0))
}
}
}
}
return true
}
...