xcode simulator - selected drop target does not match location of drag preview

After upgrading to Xcode 14, I noticed that the location where a dragged item is dropped in the simulator is not the location where the drag preview is displayed. This issue did not exist in my previous version of xcode.

By using the function dropEntered in the corresponding drop delegate, I see that when I drag an item into a point, say (row, col), on a grid in my UI view, as displayed by the preview, the drop delegate interprets it as entering into the point (row + 1, col).

The following warning appears in the Xcode output:

[Assert] CLIENT APP ERROR - Neither the view or container of the UITargetedPreview is currently in a window. This is in violation of UIDragInteraction API contract and can cause a severe visual glich. THIS IS A CLIENT APP BUG and will soon be a hard assert. PLEASE FIX ME

My guess is that the mismatch I see between the drag preview and the drag delegate's notion of the drop location is a manifestation of the visual glitch referred to in this warning.

But unfortunately, I don't understand how this warning relates to my drag and drop interactions, and how to fix the violation.

My entire drag and drop occurs within a high-level view that includes both the drag source view and the drop target views as descendants. So I don't understand what is meant by:

"Neither the view or container of the UITargetedPreview is currently in a window."

in my case.

Also, in checking the documentation of UIDragInteraction I did not see information about its contract referred to in the warning.

How should I go about fixing this violation and hopefully in the process fixing the mismatch between what is shown in the drag preview, and what is understood by the drop delegate to be the drop target?

My IOS deployment target is 15.2.

Many thanks.

Azad

Hello bro Have you experienced any issues with buttons inside UITableViewCells?

I have not experienced issues with UITableViewCells. Actually, I am creating my grid "manually" by using HStacks and VStacks.

Azad

I ended up removing my actual parameter for the preview. That gets rid of the problem. In other words, to work around the issue I had to give up on customizing the drag preview. Here is my modification with the offending custom preview commented out:

.onDrag(dragItemProvider /*, preview: { Text("(char)") } */ )

Was I not providing the preview parameter correctly here?

Thanks.

Azad

To work around this issue, I ended up removing my explicit preview parameter in my call to onDrag:

.onDrag(dragItemProvider /*, preview: { Text("(char)") } */ )

The default preview works as expected and is good enough for my current needs.

However, the question remains: was my original use of the explicit preview parameter (which I had to comment out) flawed somehow?

Thanks.

Azad

xcode simulator - selected drop target does not match location of drag preview
 
 
Q