reports icon indicating copy to clipboard operation
reports copied to clipboard

FB7367473: SwiftUI's `.onMove()` stops working if a view has a double-click tap action on macOS

Open sindresorhus opened this issue 6 years ago • 4 comments

  • Date: 2019-10-11
  • Resolution: Open
  • Area: SwiftUI Framework
  • OS: macOS 10.15
  • Type: Incorrect/Unexpected Behavior

Description

I have a list of rows that can be reordered with dragging, but I also want to add the ability to double-click a row to edit it. The problem is that when I add .onTapGesture(count: 2) {} to a row, the row can no longer be dragged and dropped.

I have attached an Xcode project that clearly illustrates the problem, I'm also including the code inline here as it's not much:

import SwiftUI

// 1. "Build & run" and then drag a row and notice the blue line indicating support for drag and drop.

struct ContentView: View {
    var body: some View {
		List {
			ForEach(0...5, id: \.self) { index in
				Text("Hello World \(index)")
					.frame(maxWidth: .infinity, maxHeight: .infinity)
					// 2. Uncomment this, "build & run", and notice how there's no longer a blue line indicator when you try to drag a row.
					// .onTapGesture(count: 2) {}
			}
			.onMove { (indexSet, index) in }
		}
    }
}

Files

swiftui-onmove-testcase.zip

sindresorhus avatar Oct 11 '19 05:10 sindresorhus

even single tap is not working

L1cardo avatar Jun 19 '20 02:06 L1cardo

Encounter the same situation. Have you found out any solution?

funway avatar Oct 04 '20 10:10 funway

Encounter the same situation. Have you found out any solution?

This answer stack overflow is an effective workaround.

And at last, I implement a customized View that wrapped an NSTableView, replace the List.

funway avatar Oct 09 '20 03:10 funway

you have to use .tag(). 2024 And still a problem...

ignaciojuarez avatar Oct 04 '24 04:10 ignaciojuarez