I use tabviews as stages for practices and I already disabled all swipe events to go between the tabs / stages. However, when you press and swipe or drag on the navigation dots you can still switch between the tabs. Preferably I would like to keep the navigation dots as a visual element, but disable any possibility of going between tabs. How can I achieve this?
This is the code for the view:
import SwiftUI
struct PracticeView: View {
let practice : Practice
@Environment(\.managedObjectContext) var viewContext
@State var stageIndex = 0
@State var practiceEnded = false
private let dotAppearance = UIPageControl.appearance()
var body: some View {
let stages = practice.practiceStage.sorted(by: { $0.order < $1.order })
VStack {
Text(practice.wrappedTitle)
TabView(selection: $stageIndex) {
ForEach(stages) { stage in
VStack {
Spacer()
if stage.type == "Timer" {
TimerStageView(stageIndex : $stageIndex, stage: stage)
} else if stage.type == "Counter"{
CounterStageView(stageIndex : $stageIndex, stage: stage)
}
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.contentShape(Rectangle())
.gesture(DragGesture())
.tag(Int(stage.order))
.fullScreenCover(isPresented: $practiceEnded, content: FinishedView.init)
}
}
.animation(.easeInOut, value: stageIndex)// 2
.indexViewStyle(.page(backgroundDisplayMode: .interactive))
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
.highPriorityGesture(DragGesture())
}
.onAppear {
dotAppearance.currentPageIndicatorTintColor = .black
dotAppearance.pageIndicatorTintColor = .gray
}
.onChange(of: stageIndex) { value in
if stageIndex == stages.count {
practiceEnded = true
}
}
}
}