I am trying to show Activity indicator view on API call in my swiftUI application. I have created the Activity Indicator view and it's working fine but I want to disable the user interaction while it is being displayed. To achieve this I have also tried allowsHitTesting(false) modifier but of no use :( When I am clicking on the button is clickable.
ContentView
import SwiftUI
struct ContentView: View {
var body: some View {
return NavigationView {
ZStack {
VStack {
Button {
//
print("Button tapped")
} label: {
Text("Tap me")
}
.frame(width: 200, height: 60)
.background(.red)
Spacer()
}
Loading()
.edgesIgnoringSafeArea(.all)
.allowsHitTesting(false)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
IndicatorView
import SwiftUI
struct Loading: View {
var body: some View {
ZStack {
BlurView()
VStack {
Indicator()
}
}.frame(maxWidth: .infinity, maxHeight: .infinity)
.allowsHitTesting(false)
}
}
//struct ActivityIndicatorView_Previews: PreviewProvider {
// static var previews: some View {
// ActivityIndicatorView(show: .constant(true))
// }
//}
struct BlurView: UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<BlurView>) -> UIVisualEffectView {
let effect = UIBlurEffect(style: .systemMaterial)
let view = UIVisualEffectView(effect: effect)
return view
}
func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<BlurView>) {
//
}
}
struct Indicator: UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<Indicator>)-> UIActivityIndicatorView {
let ind = UIActivityIndicatorView(style: .medium)
ind.startAnimating()
return ind
}
func updateUIView(_ uiView: UIActivityIndicatorView, context: Context) {
//
}
}

.allowsHitTesting(false), works for me, on a real device.