This commit is contained in:
Daniel Arantes Loverde
2026-06-03 14:31:11 -03:00
parent 69dd67b8a5
commit 74848192a0
28 changed files with 134 additions and 617 deletions

View File

@@ -5,56 +5,6 @@ extension Notification.Name {
static let snackbarDidChange = Notification.Name("snackbarDidChange")
}
#if os(Android)
@MainActor
final class SnackbarCenter {
static let shared = SnackbarCenter()
var current: SnackbarMessage?
private var dismissTask: Task<Void, Never>?
func show(
title: String,
style: SnackbarStyle = .info,
icon: String? = nil,
duration: TimeInterval = 3.5,
action: (() -> Void)? = nil
) {
dismissTask?.cancel()
current = SnackbarMessage(
title: title,
style: style,
iconSystemName: icon,
duration: duration,
action: action
)
notifyChange()
dismissTask = Task { [weak self] in
let nanos = UInt64(max(0.2, duration) * 1_000_000_000)
try? await Task.sleep(nanoseconds: nanos)
guard !Task.isCancelled else { return }
self?.dismiss(animated: true)
}
}
func handleTap() {
let action = current?.action
dismiss(animated: true)
action?()
}
func dismiss(animated: Bool) {
dismissTask?.cancel()
dismissTask = nil
current = nil
notifyChange()
}
private func notifyChange() {
NotificationCenter.default.post(name: .snackbarDidChange, object: nil)
}
}
#else
@MainActor
final class SnackbarCenter: ObservableObject {
static let shared = SnackbarCenter()
@@ -105,7 +55,6 @@ final class SnackbarCenter: ObservableObject {
}
}
}
#endif
enum SnackbarStyle: Sendable {
case info