I need to temporarily hide the Back Button in a view during an asynchronous operation. I want to prevent user from leaving the view before the operation completes.
It's possible to hide it permanently using .navigationBarBackButtonHidden(true). But, then obviously user can't go back in this case, so they are stuck. What am I missing?
Here is a contrived example to demonstrate:
struct TimerTest: View {
@State var isTimerRunning = false
var body: some View {
Button(action:self.startTimer) {
Text("Start Timer")
}
.navigationBarBackButtonHidden(isTimerRunning)
//.navigationBarBackButtonHidden(true) // This does hide it, but then it can't be unhidden.
}
func startTimer()
{
self.isTimerRunning = true
_ = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { timer in
print("Timer fired!")
self.isTimerRunning = false
}
}
}
