56 lines
1.5 KiB
Swift
56 lines
1.5 KiB
Swift
import SwiftUI
|
|
|
|
struct ToastView: View {
|
|
let message: String
|
|
@Binding var isShowing: Bool
|
|
|
|
var body: some View {
|
|
if isShowing {
|
|
VStack {
|
|
HStack(spacing: 8) {
|
|
Text(message)
|
|
.font(.mealMoodSmall)
|
|
.foregroundColor(.white)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
.padding(.horizontal, 20)
|
|
.padding(.vertical, 12)
|
|
.background(
|
|
Capsule()
|
|
.fill(Color.mealMoodCoral.opacity(0.95))
|
|
.shadow(color: .black.opacity(0.1), radius: 8, y: 4)
|
|
)
|
|
|
|
Spacer()
|
|
}
|
|
.padding(.top, 8)
|
|
.transition(.move(edge: .top).combined(with: .opacity))
|
|
.onAppear {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
|
|
withAnimation(.easeOut) {
|
|
isShowing = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ToastModifier: ViewModifier {
|
|
@Binding var isShowing: Bool
|
|
let message: String
|
|
|
|
func body(content: Content) -> some View {
|
|
ZStack {
|
|
content
|
|
ToastView(message: message, isShowing: $isShowing)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension View {
|
|
func toast(isShowing: Binding<Bool>, message: String) -> some View {
|
|
modifier(ToastModifier(isShowing: isShowing, message: message))
|
|
}
|
|
}
|