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.
I'm not sure if I understood your problem correctly. I guess what you want to do is to keep onTapGesture, Button and List's scroll functionalities all them working, except when a drag event occurs.
If you place the simultaneousGesture in the ForEach instead of assigning it to the List, then they all work, except when you drag over the Text or Button elements. In this case, the scroll does not work.