Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Are Presentation Detents supported on iPad?

So I have a minimum target of iOS 16, am using .sheet() with .presentationDetents([.medium]) and it works fine on iOS (iPhone). But when I load it on iPadOS it's always a fullsized sheet, seemingly ignoring the presentation detents. Here is a minimal reproducable code that demonstrates this behaviour.

import SwiftUI

struct ContentView: View {
    @State var shouldShowSheet: Bool = false
    
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
            
            Button("Show Sheet") {
                shouldShowSheet.toggle()
            }
        }
        .padding()
        .sheet(isPresented: $shouldShowSheet, content: {
            VStack {
                Text("Some content")
                Text("Some more content")
                Text("Even more content")
                
                Button("Dismiss Sheet") {
                    shouldShowSheet.toggle()
                }
            }
            .presentationDetents([.medium])
        })
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Below are screenshots of the same code running on iOS and running on iPadOS enter image description here

enter image description here

I tried using .fraction, .medium, .height and none of them had any effect on iPad sheets. The sheet is always a full-sized one as shown in the image. But on iOS(iPhone) it works as expected.

I'm expecting sheets on iPads to also respect the presentation detents. How can I get different sized sheets on iPad?

like image 222
raynertanxw Avatar asked Nov 23 '25 13:11

raynertanxw


1 Answers

You might be looking for the new presentationSizing(_:) API that is available in iOS 18+.

It allows configuring the shape and dimension of the modal presented sheet. From there you may build your own detent behavior on a regular-regular size class window such as full screen iPad.

like image 196
yo1995 Avatar answered Nov 26 '25 13:11

yo1995



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!