Just for the record, I am experiencing this issue as well. I have a simple TabView:
import SwiftUI
struct HomeTabbedView: View {
var body: some View {
TabView {
RehearsalsView()
.tabItem {
Image(systemName: "calendar.circle.fill")
Text("Rehearsals")
}
ProfileWrapperView()
.tabItem {
Image(systemName: "person.crop.circle.fill")
Text("User Profile")
}
}
}
}
The ProfileWrapperView consists of the following:
import SwiftUI
struct ProfileWrapperView: View {
@EnvironmentObject var portal: Portal
@State var draftAdult: Adult = Adult.default
var body: some View {
if (portal.adult) != nil {
ProfileEditView(adult: $draftAdult)
.onAppear {
self.draftAdult = self.portal.adult!
print("ProfileEditView appearing")
}
.onDisappear {
self.portal.adult! = self.draftAdult
print("ProfileEditView disappearing")
}
} else {
Text("No adult data found.")
}
}
}
When the user switches tabs from the User Profile tab to the Rehearsals tab, the onDisappear handler is called (expected) immediately followed by the onAppear handler (unexpected). I'm looking into submitting a bug report now. (This will be my first time doing this, so wish me luck. :) If anyone has a workaround for this, please let me know.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: