0

The problem I'm facing is with competing gestures.

  1. There's a DragGesture on the parent view to allow the user to return to the previous screen.
  2. Then theres a list, which is a child view, that has a swipeAction for its own child views.

These two gestures are competing to recognize the input leading to the clunkiness I'm experiencing

struct PracticeView: View {
    var body: some View {
        ScrollViewReader { scrollView in
            VStack(spacing: 0) {
                
                ScrollView(showsIndicators: false) {
                    VStack(spacing: 0) {
                        someList()
                    }
                }
            }
        }
        .gesture(
            DragGesture()
                .onEnded({ value in
                    if value.startLocation.x < 50 && value.translation.width > 80 {
                        print("back swipe")
                    }
                })
        )
    }
    
    private func someList() -> some View {
        List {
            ForEach(0..<10) { item in
                Button(action: {
                    print("Tapped button #\(item)")
                }, label: {
                    Text("Description: Lorem ipsum dolor sit amet, 
                          consectetur adipiscing elit, sed do eiusmod tempor 
                          incididunt ut labore et dolore magna aliqua. 
                          Massa vitae tortor condimentum lacinia quis vel. 
                          Et malesuada fames ac turpis egestas maecenas pharetra convallis.")
                })
                .swipeActions {
                    Button {
                        print("Tapped swipe #\(item)")
                    } label: {
                        Text("Tap me")
                    }
                    
                }
                .listRowInsets(EdgeInsets())
            }
        }
        .frame(height: 800)
        .background(Color.gray.opacity(0.2))
        .listStyle(.plain)
    }
}

I've seen solutions for dealing with multiple gestures that include using 'simultaneousGesture'. I tried applying it to the DragGesture but that didn't make a difference, and I'm not able to apply it to the SwipeActions

0 Answers0