1

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?

raynertanxw
  • 83
  • 1
  • 9
  • This might be a SwiftUI bug because presentation detents do work on iPad in UIKit. – Geoff Hackworth Jun 29 '23 at 16:25
  • This isn't a bug. This is showing as expected. If you are in a smaller SplitView, I believe it works as on iPhone. – Yrb Jun 29 '23 at 17:21
  • So it's expected to be a fullsize sheet if it's size class .regular, and still show as a presentation detents respecting sheet when it's .compact for example if splitview? I tried looking for documentation stating this but could not seem to find it. And if so, what can I do to have sheet behaviour on .compact, and have a smaller alternative similar to sheet style of presentation on the iPad when it's size class .regular? – raynertanxw Jun 30 '23 at 08:13

0 Answers0