-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fa2f3d
commit 123f85d
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// FeedbackGeneratorClientInterface.swift | ||
// FeedbackGeneratorClient | ||
// | ||
// Created by devMinseok on 8/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import Dependencies | ||
import DependenciesMacros | ||
|
||
@DependencyClient | ||
public struct FeedbackGeneratorClient { | ||
public var notification: @Sendable (UINotificationFeedbackGenerator.FeedbackType) async -> Void | ||
public var selectionChanged: @Sendable () async -> Void | ||
public var impactOccurred: @Sendable (UIImpactFeedbackGenerator.FeedbackStyle) async -> Void | ||
} | ||
|
||
extension FeedbackGeneratorClient: TestDependencyKey { | ||
public static let previewValue = Self() | ||
public static let testValue = Self() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// FeedbackGeneratorClient.swift | ||
// FeedbackGeneratorClient | ||
// | ||
// Created by devMinseok on 8/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import FeedbackGeneratorClientInterface | ||
|
||
import Dependencies | ||
|
||
extension FeedbackGeneratorClient: DependencyKey { | ||
public static let liveValue: FeedbackGeneratorClient = .live() | ||
|
||
public static func live() -> FeedbackGeneratorClient { | ||
return .init( | ||
notification: { type in | ||
let generator = await UINotificationFeedbackGenerator() | ||
await generator.notificationOccurred(type) | ||
}, | ||
selectionChanged: { | ||
let generator = await UISelectionFeedbackGenerator() | ||
await generator.selectionChanged() | ||
}, | ||
impactOccurred: { style in | ||
let generator = await UIImpactFeedbackGenerator(style: style) | ||
await generator.impactOccurred() | ||
} | ||
) | ||
} | ||
} |