기본제공하는 Sheet의 경우 내가 구현하고자 하는 기능을 제대로 구현 할 수 없었다
[SwiftUI] Sheet Background Color
import SwiftUI
struct DynamicSheetView<Content: View>: View {
@Environment(\\.dismiss) private var dismiss
private let backgroundColor: Color
private let content: () -> Content
init(backgroundColor: Color = .black.opacity(0.2), content: @escaping () -> Content) {
self.backgroundColor = backgroundColor
self.content = content
}
var body: some View {
ZStack(alignment: .bottom) {
backgroundColor
.ignoresSafeArea()
.onTapGesture {
dismiss()
}
content()
.cornerRadius(radius: 16, corners: [.topLeft, .topRight])
.transition(.opacity.combined(with: .move(edge: .bottom)))
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.ignoresSafeArea()
.transParentBackground(.clear)
}
}
import SwiftUI
struct ExampleDynamicHeightSheetView: View {
@State var selectedDetent: PresentationDetent = .height(UIScreen.main.bounds.height)
static private var sheetViewHeight: CGFloat = 0
@State private var showSheet: Bool = false
var body: some View {
ZStack {
VStack {
Button(action: {
showSheet = true
}) {
Text("Sheet Open")
}
}
.sheet(isPresented: $showSheet) {
DynamicSheetView() {
VStack {
Text("다이나믹 시트 뷰 입니다!")
.padding(.vertical, 130)
}
.frame(maxWidth: .infinity)
.background(.white)
}
}
}
}
}