Post

Replies

Boosts

Views

Activity

Reply to Task, onAppear, onDisappear modifiers run twice
I was able to reproduce this on iOS 17 by animating the view transitions by changing the top level MyApp to: @main struct MyApp: App { @State private var store = Store() var body: some Scene { WindowGroup { if store.shown { ContentView() .transition(.move(edge: .bottom)) } else { EmptyView() .transition(.move(edge: .bottom)) } } .environment(store) } } and the DetailView to: struct DetailView: View { @Environment(Store.self) private var store var body: some View { Button("Pop to top") { withAnimation { store.shown = false } } .task { print("DetailView task executed") } .onAppear { print("DetailView appeared") } .onDisappear { print("DetailView disappeared") } } } By the way, this only happens in this simple reproducer if the DetailView is shown from the ContentView within the NavigationView.
Oct ’24