Dismissing a sheet leads to broken button

The code below renders a view with a navigation bar. A plus button is placed on the navigation bar which opens a sheet. After closing this sheet view programmatically the plus button of the first view won't react anymore. Is this an iOS bug or is the code incorrect?



import SwiftUI

struct ContentView: View {
    
    @State var isAddPresented = false
    
    
    var body: some View {
        
        NavigationView {
            Text("Tap plus to add item")
                .navigationBarTitle("Main Screen Title")
                .navigationBarItems(trailing:
                    Button(action: {
                        self.isAddPresented = true
                    }) {
                        Image(systemName: "plus")
                    }
            )
                .sheet(isPresented: $isAddPresented,
                       onDismiss: {
                        self.isAddPresented = false
                }) {
                    NavigationView {
                        Text("Tap on save")
                            .navigationBarTitle("Add something")
                            .navigationBarItems(leading: Button(action: {self.isAddPresented = false}, label: {Text("Save")}))
                        
                    }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
I have the same problem. I have also found that buttons placed in a scroll view can become broken after a sheet dismissal. A button is more likely to become broken when its position is affected by the change of the scroll view’s contents‘ state(s) caused by changing the corresponding binding(s) in the sheet. After the problem occurred, scrolling in any direction seems to correct the issue, making scrolling a nice workaround. This workaround works on buttons in the navigation bar as well.
This is a known issue with NavigationView in SwiftUI. In my app i resolved the using the following trick:

Code Block swift
struct ContentView: View {
@Environment(\.presentationMode) var presentation
var body: some View {
NavigationView {
}
}
}

That triggered the correct presentation mode for me and resolves the issue where the navigation buttons become unresponsive.

Howdy folks! Please try again on the latest platform releases and file feedback if you see more issues! A reduced sample project would be excellent to include.

https://feedbackassistant.apple.com 
This sort of works. The downside that i'm seeing is that you can no longer dismiss sheets by swiping down. I'm on Xcode 12.2.

This hack on StackOverflow sort of works too but i'm not in a situation where I've got a subview presenting the sheet and doing binding to force the id of the root to change seems awful. Not sure what how to best solve this.

https://stackoverflow.com/questions/60485329/swiftui-modal-presentation-works-only-once-from-navigationbaritems


I can't believe this is still happening on Xcode 15.

The only workaround that seemed to solve it in my situation was quite simple: Changing the presentation mode from .automatic (which is .pageSheet on iOS >=13 in my understanding) to .fullScreen (the previous default). Might not be 100% the desired UX for everyone, but after some hours of trial and error I found it quite close enough.

I suppose the pure SwiftUI equivalent would be to use .fullScreenCover (iOS >=14) instead of .sheet, but I didn't try that, as I'm presenting a UIDocumentPickerViewController programmatically for unrelated reasons.

The issue with the button in navigation bar being unresponsive when the sheet is dismissed is still there in Xcode 13.1 (when user scrolls the button becomes responsive on tap in navigation bar). Is there any work being done to fix this issue?

This is quite big issue from UX experience for my customers as they think the bug is on our side. https://stackoverflow.com/questions/60485329/swiftui-modal-presentation-works-only-once-from-navigationbaritems

For some reason this bug is solved in Xcode 13.2.1 for the Simulator, but not for an actual device.

It's still happening in Xcode 13.2.1(13C100).

this is still happening with me too!

So I had a similar issue, after dismissing a sheet presented on a view, the view hierarchy gets messy and I could see in the 3D debugger that the frame of my button has been moved from its original position . Changing .sheet to .fullScreenCover solved the issue. I believe this is a swift UI bug. Xcode Version : 13.4.1 on iOS 15.5

Dismissing a sheet leads to broken button
 
 
Q