I need to use a List for reusability that it provided and disable the scroll based on adding simultaneousGesture
with DragGesture(minimumDistance: 0.0)
to support iOS 15. scrollDisabled
is only for iOS 16.
So when adding the gesture to the list onTapGesture
and Button
is not working inside each row of my list.
Here is a sample code:
ZStack {
List {
ForEach(0..<10, id:\.self) { index in
VStack {
Text("Sample text \(index)")
.onTapGesture {
print("Sample Text tapped \(index)")
}
Button("Sample button \(index)") {
print("Sample button tapped \(index)")
}
.buttonStyle(.bordered)
.frame(height: 50)
}
.frame(height: 100)
}
}
.simultaneousGesture(
DragGesture(minimumDistance: 0.0)
.onChanged({ _ in
print("Drag onChanged")
})
.onEnded({ _ in
print("Drag onEnded")
})
)
}
if we set the minimumDistance
to 0.1
tapGesture and button will work, but the scroll is not disabled anymore.
Do you have any idea or workaround? Thanks.