Skip to content

fix compilation error for macOS #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions Sources/AsyncButton/AsyncButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ public struct AsyncButton<Label> : View where Label : View {
@State private var operations: [AsyncButtonOperation] = []
@State private var showingErrorAlert = false
@State private var localizedError: AnyLocalizedError?

private let generator = UINotificationFeedbackGenerator()


#if os(iOS)
private let generator = UINotificationFeedbackGenerator()
#endif

@State private var tint: Color?

var operationIsLoading: Bool {
Expand Down Expand Up @@ -46,7 +48,9 @@ public struct AsyncButton<Label> : View where Label : View {
operations.append(.loading(actionTask))
Task {
if options.contains(.enableNotificationFeedback) {
generator.prepare()
#if os(iOS)
generator.prepare()
#endif
}
let result = await actionTask.result
let index = operations.lastIndex { operation in
Expand All @@ -57,14 +61,16 @@ public struct AsyncButton<Label> : View where Label : View {
}
}
operations[index!] = .completed(actionTask, result)
if options.contains(.enableNotificationFeedback) {
switch result {
case .success:
generator.notificationOccurred(.success)
case .failure:
generator.notificationOccurred(.error)
#if os(iOS)
if options.contains(.enableNotificationFeedback) {
switch result {
case .success:
generator.notificationOccurred(.success)
case .failure:
generator.notificationOccurred(.error)
}
}
}
#endif
if options.contains(.enableTintFeedback) {
withAnimation(.linear(duration: 0.1)) {
switch result {
Expand Down