Initial commit

This commit is contained in:
2026-06-22 11:28:01 +08:00
commit ace9c94359
84 changed files with 8899 additions and 0 deletions

View File

@ -0,0 +1,69 @@
//
// ToastCenter.swift
// suixinkan
//
// Created by Codex on 2026/6/18.
//
import Observation
import SwiftUI
@MainActor
@Observable
/// Toast
final class ToastCenter {
fileprivate var message: String?
/// Toast
func show(_ message: String) {
self.message = message
}
/// Toast
func dismiss() {
message = nil
}
}
/// Toast Toast
private struct GlobalToastOverlay: ViewModifier {
@Environment(ToastCenter.self) private var toastCenter
func body(content: Content) -> some View {
content
.overlay(alignment: .top) {
if let message = toastCenter.message {
HStack(spacing: 10) {
Image(systemName: "exclamationmark.triangle.fill")
.font(.system(size: 14, weight: .semibold))
Text(message)
.font(.system(size: 13, weight: .medium))
.lineLimit(2)
Spacer(minLength: 0)
Button("关闭") {
toastCenter.dismiss()
}
.font(.system(size: 13, weight: .semibold))
}
.foregroundStyle(.white)
.padding(.horizontal, 14)
.padding(.vertical, 10)
.background(Color.black.opacity(0.78), in: RoundedRectangle(cornerRadius: 12))
.padding(.horizontal, 16)
.padding(.top, 10)
.transition(.move(edge: .top).combined(with: .opacity))
}
}
.animation(.easeInOut(duration: 0.18), value: toastCenter.message)
}
}
extension View {
/// Toast
func globalToastOverlay() -> some View {
modifier(GlobalToastOverlay())
}
}