Skip to content

Commit

Permalink
Support macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
kemkriszt committed Oct 7, 2024
1 parent 74ec41b commit 0987fdb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "ToastyUI",
platforms: [.iOS(.v15)],
platforms: [.iOS(.v15), .macOS(.v14)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
Expand Down
20 changes: 20 additions & 0 deletions Sources/Toast/FeedbackGenerator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// FeedbackGenerator.swift
// ToastyUI
//
// Created by Krisztián Kemenes on 07.10.2024.
//

#if canImport(UIKit)
import UIKit
#endif

struct FeedbackGenerator {
@MainActor
func generateFeedback() {
#if canImport(UIKit)
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.warning)
#endif
}
}
9 changes: 2 additions & 7 deletions Sources/Toast/Toast.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import SwiftUI
import UIKit

fileprivate let toastTimeInterval: TimeInterval = 5

public struct ToastWrapper: ViewModifier {
@State private var activeToast: Toast?
@GestureState private var dragHeight: CGFloat = 0
private let feedbackGenerator = FeedbackGenerator()

public func body(content: Content) -> some View {
content
.environment(\.showToast) { newToast in
withAnimation {
self.activeToast = newToast
hapticFeedback()
feedbackGenerator.generateFeedback()
}
}
.onChange(of: activeToast) { newValue in
Expand Down Expand Up @@ -49,11 +49,6 @@ public struct ToastWrapper: ViewModifier {
}
}

private func hapticFeedback() {
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.warning)
}

private func dragMapper(_ value: CGFloat) -> CGFloat {
if value < 0 {
value
Expand Down

0 comments on commit 0987fdb

Please sign in to comment.