ToastKit is a lightweight and fully customizable Swift package that helps you display informative toast messages in your app. It’s easy to use, supports
various built-in toast styles like success, warning, info, error, with icons.... and also allows full customization for your specific needs.
You can quickly use ready-made toasts or create your own custom toast view with complete control over layout, colors, animations, icons, and more.
The color type or style of the toast (.success, .error, .info, .warning, .custom(Color)).
iconName
String?
nil
Optional name of a custom icon (from asset).
iconSize
CGFloat?
24
Size of the custom icon.
iconColor
Color?
.white
Color of the custom icon.
transitionType
ToastTransitionType
.move(edge: .top)
The transition animation for how the toast appears/disappears.
animation
Animation
.snappy
Animation used to present and dismiss the toast.
vDirection
VerticalDirection
.top
Vertical position of the toast (.top or .bottom).
titleFontColor
Color
.white
The color of the toast message text.
maxWidth
Bool
false
If true, toast takes maximum available width.
layoutDirection
LayoutDirection
.leftToRight
Layout direction of content (.leftToRight or .rightToLeft).
🍞 Toast Stack
With ToastStackManager, you can show toasts at the same time!
Certainly, you can utilize toast stacks from your view model. Here’s an example:
// in your ViewModel
import ToastKit
import Combine
finalclassViewModel:ObservableObject{lettoastManager:ToastStackManagerinit(toastManager:ToastStackManager=ToastStackManager()){self.toastManager = toastManager
}@MainActorfunc foo(){
// Your logic
toastManager.show(title:"foo success toast", toastColor:.success, autoDisappearDuration:3.0)
// Your logic
toastManager.show(title:"foo info toast", toastColor:.info)}}
in your view
import ToastKit
import SwiftUI
structProfileView:View{@StateObjectprivatevarvm:ViewModelinit(vm:ViewModel=ViewModel()){
_vm =StateObject(wrappedValue: vm)}varbody:someView{ZStack{
// Your view
ToastStackView(vm: vm.toastManager)
// Alternatively, you can utilize it with a custom transition.
ToastStackView(vm: vm.toastManager, transitionType:.move(edge:.trailing).combined(with:.opacity))}}}
ToastStackView Configuration ⚙️
Parameter
Type
Default Value
Description
title
String
-
The main message displayed in the toast.
toastColor
ToastColorTypes
-
The color type or style of the toast.
autoDisappearDuration
TimeInterval
2.0
Duration before toast disappears.
ToastStackManager Configuration ⚙️
Parameter
Type
Default Value
Description
vm
ToastStackManager
-
The view model that manages
transitionType
AnyTransition
-
Transition animation for appearing/disappearing.
⚠️ Alternatively, you can utilize the .toast method to construct a fully customizable toast by specifying the following parameters: