dropDestination does not work inside List

I've discovered an issue with using iOS 16's Transferable drag-and-drop APIs for SwiftUI. The dropDestination modifier does not work when applied to a subview of a List.

This code below will not work, unless you replace the List with a VStack or any other container (which, of course, removes all list-specific rendering).

The draggable modifier will still work and the item will drag, but the dropDestination view won't react to it and neither closure will be called.

struct MyView: View {
    
    var body: some View {
        List {
            Section {
                Text("drag this title")
                    .font(.largeTitle)
                    .draggable("a title")
            }
            Section {
                Color.pink
                    .frame(width: 400, height: 400)
                    .dropDestination(for: String.self) { receivedTitles, location in
                        true
                    } isTargeted: {
                        print($0)
                    }
            }
        }
    }
    
}

Has anyone encountered this bug and perhaps found a workaround?

Replies

Hello,

Which platform are you encountering an issue on? This code works on macOS 13.4 beta (22F5049e).

  • Hi @gchiste, I'm seeing this on iOS 16.4, simulator and physical device. I'm using Xcode 14.3 to build.

Add a Comment

@foreignfilm I can confirm this not working as expected under iOS, while working as expected under macOS.

It doesn't work under iOS when drag source and drop destination are contained within the same list. i.e., you're able to drop items from another view that is not part of the same list.

This is still unresolved on iOS 17 beta 1.

I can confirm it's also not working for me when I want to drag and drop items between two sections in a list. If I remove the list, as described above, it works but within one list declaration I am not able to.

This is still an issue in Xcode 15.0 Beta 4

@gchiste I have filed a feedback FB12980427 (contains sample code, videos)

I really hope that the bug gets fixed, I have filed it under SwiftUI as CoreTransferable wasn't available in the frameworks list.

Yes, this doesn't work on iOS but works on macOS.

I have tested on iOS 17 beta using Xcode 15 beta 6.

Hi, Xcode 15, release candidate. iOS 17. macOS 14. Still doesn't work.

List -> Categories -> Items.

Drag & Drop item to another category. Works fine on iOS. Doesn't work on macOS - the item remains stuck above the target category view and the operation is stuck and cannot be completed.

  • I ran into this as well, and while there is unfortunately still no fix for this, I came up with a workaround that could work for me (until it gets fixed I guess):

    if a list is empty, I show an ContentUnavailableView and bind a .dropDestination to itif the list is not empty, I will bind a .dropDestination to each list cell

    That enables me to at least perform something on a drop.

  • Could you show me what that code looks like? I have a List of Characters that have builds, I want to move builds to another character if needed. I have a draggable modifier on the build, and a destination on the character, but it doesn't do anything :')

Add a Comment

Hi, XCode 15, iOS 17.2., macOS 14.2.1

This is what works and what doesn't work for me.

MacOS: Trying to drag and drop an item from a list into another list doesn't work. MacOS: Trying to drag and drop a STRING from a list into another list work fine. MacOS: Trying to drag and drop a STRING from a list into same list work fine.

iOS: Trying to drag and drop an item from a list into a list does work. iOS: Trying to drag and drop a string from a list into another list does work.
iOS: Trying to drag and drop a string from a list into a same list doesn't work.

I wonder if it is a bug or a feature and it is a way to develop drag and drop of a string from a list to the same list? I hope this inconsistency is going to be fix any time soon.