Using Swift5.3.2, iOS14.4.1, XCode12.4,
I am showing a modal sheet in SwiftUI.
Unfortunately, the sheet completely freezes whenever an underlying parent-View re-renders/updates.
I am absolutely clueless on how I can circumvent that issue. Any ideas ?
Here is the parent View:
import SwiftUI
struct ParentTrialView: View {
@State var currentDate = Date()
@State private var showingGrid = false
let timer = Timer.publish(every: 10, on: .main, in: .common).autoconnect()
var body: some View {
NavigationView {
Text("\(currentDate)")
.onReceive(timer) { input in
currentDate = input
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
showingGrid.toggle()
}) {
Image(systemName: "square.grid.3x3")
}
.sheet(isPresented: $showingGrid) {
ChildTrialView(onDismiss: {
showingGrid = false
})
}
}
}
}
}
}
And here is the child View:
import SwiftUI
struct ChildTrialView: View {
var onDismiss: () -> ()
var body: some View {
NavigationView {
Text("Trial")
.onTapGesture {
onDismiss()
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
onDismiss()
}) {
Text("Cancel")
}
}
}
}
}
}
If you, for example, set the timer to 20 seconds. Then you have 20 seconds where everything works on the child View (i.e. it's tap-Gesture works, and also its Cancel button to close the child-View works perfectly).
However, when the timer fires an update to the parent-View, then no action works on the child-View anymore !!
I am more than desperate with this SwiftUI problem.
Any solution on this ?