SwiftUI ScrollView with rows with gesture won't recognize scroll
Asked Answered
C

0

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
        })
}
}
Comparison answered 24/9, 2019 at 2:26 Comment(1)
I had the same problem and was unable to solve it. Though you can find a workaround in replies. #57700896Spiral

© 2022 - 2024 — McMap. All rights reserved.