In my app, the above workaround caused another problem. But, I could avoid it by changing the next code using DispatchQueue.main.async.
I hope this issue will be resolved by the public release of iOS 17.
struct SampleSection: View {
@State private var isLoaded = false
var body: some View {
let _ = Self._printChanges()
Group {
if !isLoaded {
Section("Header") {}
.hidden()
} else {
Section("Header") {
Text("Text")
}
}
}
.onAppear {
DispatchQueue.main.async { // or Task { @MainActor in
NSLog("SampleSection onAppear.")
isLoaded = true
}
}
.onDisappear() {
DispatchQueue.main.async { // or Task { @MainActor in
NSLog("Sample Section onDisappear.")
isLoaded = false
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: