UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Listening to LongPressGesture on Subview makes parent TabView pager unswipeable

Forums > SwiftUI

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

1      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.