wake-ios/wake/View/Components/SheetModal.swift
2025-09-02 15:37:05 +08:00

69 lines
2.7 KiB
Swift

import SwiftUI
struct SlideInModal<Content: View>: View {
@Binding var isPresented: Bool
let onDismiss: () -> Void
let content: () -> Content
// -
private let animation = Animation.spring(
response: 0.8, // 使
dampingFraction: 1, // 使
blendDuration: 0.8 // 使
)
var body: some View {
ZStack(alignment: .leading) {
//
if isPresented {
Color.clear
.contentShape(Rectangle())
.edgesIgnoringSafeArea(.all)
.transition(.opacity)
.zIndex(1)
.onTapGesture {
withAnimation(animation) {
isPresented = false
onDismiss()
}
}
//
ZStack(alignment: .leading) {
//
VStack(spacing: 0) {
//
Color.clear
.frame(height: UIApplication.shared.windows.first?.safeAreaInsets.top ?? 0)
//
content()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.bottom, UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0)
}
.frame(width: UIScreen.main.bounds.width * 0.8)
.frame(maxHeight: .infinity)
.background(Color(.systemBackground))
.edgesIgnoringSafeArea(.vertical)
}
//
.background(
RoundedRectangle(cornerRadius: 0)
.fill(Color(.systemBackground))
.shadow(
color: .black.opacity(0.3),
radius: 10,
x: 5,
y: 0
)
)
.offset(x: isPresented ? 0 : -UIScreen.main.bounds.width)
.zIndex(2)
.transition(.move(edge: .leading))
.animation(animation, value: isPresented)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.edgesIgnoringSafeArea(.all)
}
}