I want to achieve similar behaviour which is in Apple Podcast app on iOS on queue screen. I want to be able to display context menu after long press on every row, except on view with image “line.3.horizontal”. Also I want to be able to drag rows, while pressing row and more importantly on image “line.3.horizontal”.
I found a solution to not display the context menu on long press on hamburger image. It is done using LongPressGesture and StateGesture variable. Unfortunately I can’t drag pressing hamburger image anymore using onMove
struct ContentView: View {
@State var items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
@GestureState var isDraggingImageView = false
var body: some View {
List {
ForEach(items, id: .self) { item in
HStack {
Text(item)
Spacer()
Image(systemName: "line.3.horizontal")
.gesture(
LongPressGesture()
.updating($isDraggingImageView, body: { value, state, _ in
state = value
})
)
}
.contextMenu(ContextMenu(menuItems: {
if isDraggingImageView {
EmptyView()
} else {
Text("Menu Item 1")
Text("Menu Item 2")
}
}))
}
.onMove(perform: move)
}
}
func move(from source: IndexSet, to destination: Int) {
items.move(fromOffsets: source, toOffset: destination)
}
}
How to make onMove and LongPressGesture to work together?