Trying to implement a TabView
with PageTabView
style in SwiftUI
, where navigation is only done programmatically, and all swipe gestures are disabled.
This solution only partially works - if you tap the screen as the selection is changing, it still interferes with the transition and causes weird effects. Also, if you scroll with two fingers the gesture still registers. I need a solution that fully disables the swipe gesture.
Code:
struct PageViewTest: View {
@State var selection: Int = 1
var body: some View {
ZStack {
Color.green.ignoresSafeArea()
TabView(selection: $selection) {
Color.red
.tag(1)
.gesture(DragGesture())
Color.blue
.tag(2)
.gesture(DragGesture())
Color.yellow
.tag(3)
.gesture(DragGesture())
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.animation(.linear, value: selection)
VStack {
Spacer()
Button(action: {
selection = selection == 3 ? 1 : selection + 1
}) {
Text("next")
.foregroundColor(.white)
.font(.title)
}
}
}
}
}
setting .disabled(true)
to the TabView
solves it, but then all of the subviews are no longer interactive.