diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/macintoshi.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/macintoshi.xcuserdatad/UserInterfaceState.xcuserstate index 8bc33bc..114a777 100644 Binary files a/.swiftpm/xcode/package.xcworkspace/xcuserdata/macintoshi.xcuserdatad/UserInterfaceState.xcuserstate and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/macintoshi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/.swiftpm/xcode/xcuserdata/macintoshi.xcuserdatad/xcschemes/xcschememanagement.plist b/.swiftpm/xcode/xcuserdata/macintoshi.xcuserdatad/xcschemes/xcschememanagement.plist index 5e8c333..724c076 100644 --- a/.swiftpm/xcode/xcuserdata/macintoshi.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/.swiftpm/xcode/xcuserdata/macintoshi.xcuserdatad/xcschemes/xcschememanagement.plist @@ -10,5 +10,18 @@ 0 + SuppressBuildableAutocreation + + ToastKit + + primary + + + ToastKitTests + + primary + + + diff --git a/Package.swift b/Package.swift index cdd87e1..0e019ab 100644 --- a/Package.swift +++ b/Package.swift @@ -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 diff --git a/README.md b/README.md index 071d1ef..6c26b4f 100644 --- a/README.md +++ b/README.md @@ -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. -![Static Badge](https://img.shields.io/badge/Swit-6.1-orange) ![Static Badge](https://img.shields.io/badge/iOS-17.0%2B-white) ![Static Badge](https://img.shields.io/badge/Version%20-%201.2.0-skyblue) ![Static Badge](https://img.shields.io/badge/LICENSE-MIT-yellow) ![Static Badge](https://img.shields.io/badge/SPM-SUCCESS-green) +![Static Badge](https://img.shields.io/badge/Swit-6.1-orange) ![Static Badge](https://img.shields.io/badge/iOS-17.0%2B-white) ![Static Badge](https://img.shields.io/badge/Version%20-%201.3.0-skyblue) ![Static Badge](https://img.shields.io/badge/LICENSE-MIT-yellow) ![Static Badge](https://img.shields.io/badge/SPM-SUCCESS-green) @@ -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. | diff --git a/Sources/ToastKit/ToastKit.swift b/Sources/ToastKit/ToastKit.swift index 444d962..2a33aef 100644 --- a/Sources/ToastKit/ToastKit.swift +++ b/Sources/ToastKit/ToastKit.swift @@ -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)