Screen presented via NavigationLink gets popped out when it's observed object changes.
Originator: | azeffin | ||
Number: | rdar://FB9109868 | Date Originated: | 18 May 2021 |
Status: | Open | Resolved: | |
Product: | SwiftUI | Product Version: | |
Classification: | Incorrect/Unexpected Behavior | Reproducible: | Yes |
Summary: Screen presented via NavigationLink gets popped out when it's observed object changes. Steps to reproduce: 1. Create SwiftUI iOS app with following implementation ``` import SwiftUI @main struct PopBug2App: App { var body: some Scene { WindowGroup { FirstView() } } } class FirstViewModel: ObservableObject { @Published var showDetails = false let id = UUID() } class SecondViewModel: ObservableObject { @Published var value = false let id = UUID() } struct FirstView: View { @StateObject private var viewModel = FirstViewModel() @StateObject private var secondViewModel = SecondViewModel() var body: some View { NavigationView { VStack { NavigationLink(destination: Text("About")) { Text("About") } NavigationLink( destination: SecondView(viewModel: secondViewModel), isActive: $viewModel.showDetails ) { EmptyView() } Button("Details") { viewModel.showDetails = true } } } } } struct SecondView: View { @ObservedObject var viewModel: SecondViewModel var body: some View { VStack { Text("Details") Button("Toggle view model value") { viewModel.value.toggle() } } } } ``` 2. Run the app 3. Tap on 'Details' button 4. Tap on 'Toggle view model value' button Observed behavior: Screen gets popped out after value in the view model changed Expected behavior: Screen stays open Note: Believe issue was introduced in iOS 14.5, because I can’t reproduce it on previous versions. Changing view hierarchy by adding another NavigationLink fixes the issue. Versions: Xcode 12.5 (12E262) iOS 14.5.1 (18E212) macOS 11.2.3 (20D91)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!