Minimal reproduzierbarer Code:
Code: Select all
import SwiftUI
class SheetViewModel: ObservableObject {
@Published var isPresented: Bool = true
}
struct RootSheetWrapper: View {
@StateObject var viewModel: SheetViewModel
var body: some View {
// Transparent host view acting as the anchor for the sheet
Color.clear
.customTransparentSheet(isPresented: $viewModel.isPresented, height: 400) {
SheetContent()
}
}
}
// Minimal version of my custom sheet extension
extension View {
func customTransparentSheet(
isPresented: Binding,
height: CGFloat,
@ViewBuilder content: @escaping () -> Content
) -> some View {
ZStack {
self
SomeOverlay()
}
self.sheet(isPresented: isPresented) {
content()
.presentationDragIndicator(.hidden)
.applyTransparentBackground()
.presentationDetents([.height(height)])
}
}
}
private extension View {
@ViewBuilder
func applyTransparentBackground() -> some View {
if #available(iOS 16.4, *) {
self.presentationBackground(.clear)
} else {
self.background(Color.clear.ignoresSafeArea())
}
}
}
Code: Select all
struct SheetContent: View {
var body: some View {
VStack(spacing: 0) {
// This image should sit behind the home indicator
Image(systemName: "star.fill")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: .infinity)
}
// This makes the background transparent, but the bottom safe area
// still clips the Red background/Image above.
// .ignoresSafeArea(.all) //
Mobile version