portico/Sources/Portico/Extensions/ToastOverlay+Extras.swift

21 lines
831 B
Swift

import Adw
extension WidgetView where Target: Adw.ToastOverlay {
/// Attaches `manager` to this overlay so ``ToastManager/addToast(_:)`` and
/// ``ToastManager/dismissAll()`` act on it.
///
/// Any toasts the manager queued before mount are flushed immediately. The
/// manager detaches on subtree teardown.
///
/// ``ToastManager`` is a reference type, so pass it directly - no
/// ``Binding`` is involved, mirroring ``View/environment(_:)``.
///
/// - Parameter manager: The manager to attach.
/// - Returns: A copy of this view with the manager attached at mount time.
public func toastManager(_ manager: ToastManager) -> Self {
appending { w, ctx in
manager._attach(w)
ctx.registry.add(SubscriptionToken { manager._detach(w) })
}
}
}