mirror of
https://github.com/Desp0o/ToastKit.git
synced 2026-06-17 14:34:30 +00:00
toast stack doc
This commit is contained in:
@@ -252,7 +252,78 @@ VStack {
|
||||
|
||||
------------
|
||||
|
||||
## ⚠️ Alternatively, you can use .toast to build a fully customizable toast by providing the following parameters ⚠️
|
||||
## 🍞 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:
|
||||
```swift
|
||||
// in your ViewModel
|
||||
|
||||
import ToastKit
|
||||
import Combine
|
||||
|
||||
final class ViewModel: ObservableObject {
|
||||
let toastManager: ToastStackManager
|
||||
|
||||
init(toastManager: ToastStackManager = ToastStackManager()) {
|
||||
self.toastManager = toastManager
|
||||
}
|
||||
|
||||
@MainActor func 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
|
||||
|
||||
```swift
|
||||
import ToastKit
|
||||
import SwiftUI
|
||||
|
||||
struct ProfileView: View {
|
||||
@StateObject private var vm: ViewModel
|
||||
|
||||
init(vm: ViewModel = ViewModel()) {
|
||||
_vm = StateObject(wrappedValue: vm)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
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:
|
||||
|
||||
##### Configuration ⚙️
|
||||
| Parameter | Type | Default Value | Description |
|
||||
|
||||
Reference in New Issue
Block a user