With iOS 18 beta which recently came out, I was curious in how to use the new .presentationSizing. Does it completely change the size of the sheet or is this only a notable feature for mac apps? Also are there any new features which make it so the .sheet can be presented above the tab bar like in the apple FindMy app.
I tried something like this but it did not work.
import SwiftUI
@available(iOS 18.0, *)
struct Test: View {
@State private var isPresented = false
var body: some View {
Button("Show Modal") {
isPresented.toggle()
}
.sheet(isPresented: $isPresented) {
ModalContentView()
.presentationSizing(SquareSizing())
}
}
}
struct ModalContentView: View {
var body: some View {
Text("This is a modal view.")
.padding()
.background(Color.blue)
.foregroundColor(.white)
}
}
@available(iOS 18.0, *)
struct SquareSizing: PresentationSizing {
func proposedSize(for subview: PresentationSizingRoot, context: PresentationSizingContext) -> ProposedViewSize {
let size = CGSize(width: 400, height: 400)
return ProposedViewSize(size)
}
}
#Preview{
if #available(iOS 18.0, *) {
Test()
} else {
// Fallback on earlier versions
}
}