I am using a tab view in my SwiftUI app. I want to disable its swipe to left and write to move to other pages. I checked
Does anyone has a solution for this?
CodePudding user response:
Have you tried .disabled(true)
?
CodePudding user response:
Actually the issue is because your views are transparent, so gesture is ignored due to failed hit testing.
The fix is to make it hit-testable explicitly with .contentShape
modifier.
Tested with Xcode 13.4 / iOS 15.5
TabView(selection: $selectedIndex) {
FirstView().tag(0)
.contentShape(Rectangle()).gesture(DragGesture()) // << here !!
SecondView().tag(1)
.contentShape(Rectangle()).gesture(DragGesture())
ThirdView().tag(2)
.contentShape(Rectangle()).gesture(DragGesture())
}.tabViewStyle(.page(indexDisplayMode: .never))