Using SwiftUI (latest XCode and testing on IOS 13.3) I'm trying to implement a long press gesture on items in a list, to allow user interaction with the individual items. The problem is that when I set "onLongPressGesture" anywhere in the list (on items, on the list itself), the list cannot be scrolled anymore. I can easily get a simple tap to work but a long press blocks scrolling.
I've put together a small example that show this issue:
struct ContentView: View
{
let data = [
"Test 1","Test 2","Test 3","Test 4","Test 5",
"Test 6","Test 7","Test 8","Test 9","Test 10",
"Test 11","Test 12","Test 13","Test 14","Test 15",
"Test 16","Test 17","Test 18","Test 19","Test 20"
]
var body: some View
{
List
{
ForEach(data,id:.self)
{
item in
Text(item).onLongPressGesture{}
}
}
}
}
If I try to drag the list pressing on any text, the list wont move. If I remove the longpress handler, it moves no matter where I press down.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…