I have confirmed that is also is a problem on iOS 14, but I can not edit this post, so just posting updates and reproducible code here:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: SecondView()) {
Text("Click Me to go to second view (MAY FREEZE)")
}.padding()
NavigationLink(destination: ThirdView()) {
Text("Go to third view first (Multi-Layer)")
}.padding()
}
}
}
}
struct SecondView: View {
@State var downloading = false
@State var message = "Please Wait"
var body: some View {
LoadingView(isShowing: $downloading, message: $message) {
VStack {
Spacer()
HStack{
Spacer()
Text("This is a second view.").padding()
Spacer()
}
Spacer()
}
}
.onAppear(perform: {
downloading = true
let twoSecondsFromNow = DispatchTime.now() + 2.0
DispatchQueue.main.asyncAfter(deadline: twoSecondsFromNow) {
downloading = false
}
})
}
}
struct ThirdView: View {
var body: some View {
NavigationLink(destination: SecondView()) {
Text("Click Me to go to second view (NO FREEZE)")
}
}
}
struct LoadingView<Content>: View where Content: View {
@Binding var isShowing: Bool
@Binding var message: String
var content: () -> Content
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .center) {
self.content()
.disabled(self.isShowing)
.blur(radius: self.isShowing ? 3 : 0)
VStack {
Text(self.message).multilineTextAlignment(.center)
ProgressView()
}
.frame(width: geometry.size.width / 2,
height: geometry.size.height / 5)
.background(Color.secondary.colorInvert())
.foregroundColor(Color.primary)
.cornerRadius(20)
.opacity(self.isShowing ? 1 : 0)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Topic:
Programming Languages
SubTopic:
Swift
Tags: