I’m having trouble getting a sheet to expand past the safe area and touch the leading and trailing edges of the screen when the device is in landscape.
Ideally the sheet would have all the benefits of using .presentationCompactAdaptation(.sheet)
and the white background would touch the horizontal edges of the screen – similar to how a sheet operates in portrait.
See image highlighting the leading and trailing edges I would like the sheet to ignore.
Using fullScreenCover
is not an option.
import SwiftUI
struct LandscapeSheetTest: View {
@State private var isSheetPresented: Bool = false
var body: some View {
VStack {
Button {
isSheetPresented.toggle()
} label: {
Text("show sheet")
}
}
.sheet(isPresented: $isSheetPresented) {
VStack {
Text("Some content here")
}
.frame(width: UIScreen.main.bounds.width) // Not necessary, but highlights how the sheet only stretches up to the safe area bounds
.presentationContentInteraction(.resizes)
.presentationCompactAdaptation(.sheet)
.presentationDetents([.height(200), .large])
}
}
}
#Preview {
LandscapeSheetTest()
}
2
Answers
This simply isn’t possible using the built in
.sheet
modifier. You would need to build your own sheet implementation or use a third-party dependency like ManySheets (https://github.com/GlennBrann/ManySheets) which does support this. Note – I’m not affiliated w/ManySheets and am simply making a suggestion to use it.