mirror of
https://github.com/Desp0o/ToastKit.git
synced 2026-06-17 14:34:30 +00:00
add dataTask for cancel ongoing tasks
This commit is contained in:
Generated
BIN
Binary file not shown.
@@ -10,5 +10,18 @@
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>ToastKit</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>ToastKitTests</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version: 6.1
|
||||
// swift-tools-version: 6.0
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -8,7 +8,7 @@ various built-in toast styles like success, warning, info, error, with icons....
|
||||
You can quickly use ready-made toasts or create your own custom toast view with complete control over layout, colors, animations, icons, and more.
|
||||
|
||||
|
||||
    
|
||||
    
|
||||
|
||||
|
||||
|
||||
@@ -349,6 +349,7 @@ struct ProfileView: View {
|
||||
| `innerVpadding` | CGFloat | `10` | Inner vertical padding. |
|
||||
| `outterHpadding` | CGFloat | `20` | Outer horizontal padding. |
|
||||
| `stackAligment` | Alignment | `.top` | Stack alignment inside the toast. |
|
||||
| `isStackMaxHeight` | Bool | `true` | occupies the maximum available height |
|
||||
| `cornerRadius` | CGFloat | `12` | Corner radius of the toast. |
|
||||
| `shadowColor` | Color | `.black.opacity(0.2)` | Shadow color. |
|
||||
| `shadowRadius` | CGFloat | `10` | Radius of the toast's shadow. |
|
||||
|
||||
@@ -6,6 +6,7 @@ import SwiftUI
|
||||
@available(macOS 14.0, *)
|
||||
@available(iOS 17, *)
|
||||
public struct CustomToast: View {
|
||||
@State private var disappearTask: Task<(), Never>?
|
||||
@Binding var isVisible: Bool
|
||||
let title: String
|
||||
let toastColor: ToastColorTypes
|
||||
@@ -239,12 +240,18 @@ public struct CustomToast: View {
|
||||
.if(isStackMaxHeight) { $0.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: stackAligment)}
|
||||
.onChange(of: isVisible) { _, newValue in
|
||||
if newValue {
|
||||
disappearTask?.cancel()
|
||||
if autoDisappear {
|
||||
Task {
|
||||
disappearTask = Task {
|
||||
try? await Task.sleep(nanoseconds: UInt64(autoDisappearDuration * 1_000_000_000))
|
||||
isVisible = false
|
||||
if !Task.isCancelled {
|
||||
isVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
disappearTask?.cancel()
|
||||
disappearTask = nil
|
||||
}
|
||||
}
|
||||
.animation(animation, value: isVisible)
|
||||
|
||||
Reference in New Issue
Block a user