7

I implemented a vertical ScrollView in SwiftUI, and then gave each row horizontal drag gesture. Somehow implementing this stopped the ScrollView drag when dragging inside a row (as to see the rest of the list) from working, i tried replacing ScrollView with List but the problem persisted.

Here's the code:

struct MyView: View {
var MyArray: [String] = ["Foo", "bar","foobar"]
var body: some View {
    ScrollView{
        ForEach(MyArray, id:\.self)
        { _ in
            Cell()
        }
    }
}
}

Cell:

struct Cell: View{
@State var draggedOffset = CGSize.zero

var body: some View {
    HStack {
        Text("Test")
    }.animation(.linear)
        .offset(x: self.draggedOffset.width)
        .gesture(DragGesture()
            .onChanged{ value in
                self.draggedOffset.width = value.translation.width

        }
        .onEnded { value in
            self.draggedOffset = CGSize.zero
        })
}
}
IMBFeedback
  • 71
  • 1
  • 3
  • 3
    I had the same problem and was unable to solve it. Though you can find a workaround in replies. https://stackoverflow.com/questions/57700396/adding-a-drag-gesture-in-swiftui-to-a-view-inside-a-scrollview-blocks-the-scroll – zh. Sep 24 '19 at 19:20

0 Answers0