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()
}