0

Here is a Tabview pager with 3 pages. The LongPressGesture is well detected, but swiping from the VStack subview has no effect. (It works if I swipe from outside the VStack though).

struct MainView: View {
    var body: some View {
        TabView {
            ForEach((1...3), id: \.self) { _ in
                VStack {}
                    .frame(width: 200, height: 200)
                    .background(.black)
                    .onLongPressGesture {
                        print("long touch detected")
                    }
            }
        }
        .tabViewStyle(.page(indexDisplayMode: .never))
    }
}

I tried replacing onLongPressGesture with simultaneousGesture, but it produces the same behavior:

.simultaneousGesture(LongPressGesture().onEnded({ _ in
    print("long touch detected")
}))

How to make Tabview pager swipeable from subviews who need to detect LongPress gestures?

ps: using onTapGesture works perfectly well and doesn't interefere with the Tabview swipe

Jérôme Boé
  • 2,752
  • 4
  • 21
  • 32

0 Answers0