Skip to content

Commit

Permalink
Fixed Swift 6 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sanzaru committed Oct 21, 2024
1 parent 7c08591 commit 99330cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Sources/SimpleToast/SimpleToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ struct SimpleToast<SimpleToastContent: View>: ViewModifier {
let options: SimpleToastOptions
let onDismiss: (() -> Void)?

@State private var timer: Timer?
@State private var offset: CGSize = .zero
@State private var isInit = false
@State private var viewState = false
@State private var cancelable: Cancellable?

private let toastInnerContent: SimpleToastContent

Expand Down Expand Up @@ -118,18 +118,19 @@ struct SimpleToast<SimpleToastContent: View>: ViewModifier {
/// Dismiss the sheet after the timeout specified in the options
private func dismissAfterTimeout() {
if let timeout = options.hideAfter, showToast, options.hideAfter != nil {
DispatchQueue.main.async { [self] in
timer?.invalidate()
timer = Timer.scheduledTimer(withTimeInterval: timeout, repeats: false, block: { _ in dismiss() })
}
cancelable = Timer.publish(every: timeout, on: .main, in: .common)
.autoconnect()
.sink { _ in
cancelable?.cancel()
dismiss()
}
}
}

/// Dismiss the toast and reset all nessasary parameters
private func dismiss() {
withAnimation(options.animation) {
timer?.invalidate()
timer = nil
cancelable?.cancel()
showToast = false
viewState = false
offset = .zero
Expand Down
1 change: 1 addition & 0 deletions Sources/SimpleToast/SimpleToastModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI

/// Protocol defining the structure of a SimpleToast view modifier
/// The basic building blocks are a boolean value determining whether to show the toast or not and an instance of a SimpleToastOptions object, which is optional.
@MainActor
protocol SimpleToastModifier: ViewModifier {
var showToast: Bool { get set }
var options: SimpleToastOptions? { get }
Expand Down

0 comments on commit 99330cc

Please sign in to comment.