Bug: SwiftUI inspector doesn't update presentation detent selection on iPhone

On iPhone .inspector is presented as a sheet so you can use .presentationDetents to determine its detents. However, SwiftUI doesn't update the presentationDetents selection binding in this case. See attached minimum example of the problem - onChange will not run and print when you swipe and change the detent of the inspector sheet.

import SwiftUI

@main
struct TestingApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    @State var showInspector = false
    @State var detent: PresentationDetent = .medium
    
    var body: some View {
        Button("Toggle Inspector") {
            showInspector.toggle()
        }
        .inspector(isPresented: $showInspector) {
            Text("Inspector Content")
                .presentationDetents([.medium, .large], selection: $detent)
        }
        .onChange(of: detent) { _, detent in
            print(detent)
        }
    }
}

#Preview {
    ContentView()
}

Thanks for the post. Using your code the block never gets called in Xcode 26, however the selection even when I expanded doesn't change neither, interesting.

 .onChange(of: detent) { _, detent in
            print(detent)
        }
.presentationDetents([.medium, .large], selection: $detent)

Both are presented. I am trying to understand a little bit more if you trying to get called when it changes to large in your sample? If that's correct?

Albert Pascual
  Worldwide Developer Relations.

Yes that's correct - the sheet does snap to the provided detents, but the selection: Binding<Bool> parameter does not update as you have seen.

Thanks for your quick answer. Would you be able to file a bug for that?

Once you open the bug report, please post the FB number here for my reference.

If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?

Albert Pascual
  Worldwide Developer Relations.

I have submitted a bug report FB20545421

Thank you for the bug report.

I would like to offer a comment. I noticed that you provided a swift file instead of a focused and simple project that would enable engineers to reproduce the issue without creating a new project.

If you're not familiar with preparing a test project, take a look at Creating a test project.

You can see the status of your feedback in Feedback Assistant. There, you can track if the report is still being investigated, has a potential identifiable fix, or has been resolved in another way. The status appears beside the label "Resolution." We're unable to share any updates on specific reports on the forums.

For more details on when you'll see updates to your report, please see What to expect after submission.

Albert Pascual
  Worldwide Developer Relations.

Thanks Albert, I've now submitted a simple project that identifies the bug.

Thanks for doing that. Lets give the engineering team sometime to figure it out. Keep an eye on the FB number.

You can see the status of your feedback in Feedback Assistant. https://feedbackassistant.apple.com/

Albert Pascual
  Worldwide Developer Relations.

Bug: SwiftUI inspector doesn't update presentation detent selection on iPhone
 
 
Q