DynamicViewContent and drop validation (macOS)

If I see it correctly, it is currently not possible to validate a drop operation on a DynamicViewContent when using dropDestination?

Just a simple example: Let's say I build a folder view on macOS where I can arrange folders freely. In this case I need to use DynamicViewContent.dropDestination to get an insertion index on drop. However, it seems that methods like dropConfiguration do not have any effect. Als dropDestionation(…, isTargeted:) seems not to be available.

Here is my sample code:


struct FolderRow: View {
    let folder: Folder

    var body: some View {
        DisclosureGroup(isExpanded: .constant(true)) {
            ForEach(folder.children) { child in
                FolderRow(folder: child)
            }
			.dropDestination(for: Folder.self) { item, idx in
                  print("Dropped at \(idx)")
			}
        } label: {
            Label(folder.name, systemImage: "folder")
                .draggable(folder)
                .dropDestination(for: Folder.self) { items, _ in
                    print("Dropped on Item")
                }
        }
		.dropConfiguration { session in
			DropConfiguration(operation: .move)
		}
    }
}

struct ContentView: View {
    @State private var folder: Folder = Folder.sampleData
    @State private var selection: Set<UUID> = []

    var body: some View {
        NavigationSplitView {
            List(selection: $selection) {
                FolderRow(folder: folder)
            }
        } detail: {
            EmptyView()
        }
    }
}

The dropConfiguration is applied on the Label (in this case the "Move" cursor is used instead of the "Copy" cursor).

Is there any way to do that or is it just an omission in Swift UI?

You could use onDropSessionUpdated(_:) to know when the closest drop session in the child view hierarchy becomes active, that would give you your drop target.

Thanks for getting back!

But this way I still can't validate the drop? For instance, I can't say that it is not allowed to drop something on Index 0? (E.g. to forbid moving something between some built-in items in the sidebar of my app)

DynamicViewContent and drop validation (macOS)
 
 
Q