-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructuring FeedbackEffect into multiple files
- Loading branch information
Showing
7 changed files
with
189 additions
and
161 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
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
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,50 @@ | ||
import UIKit | ||
|
||
/// An enum describing the different kinds of haptic feedback the taptic engine is capable of producing. | ||
/// For use in `FeedbackEffect`, to give the user feedback when it's desired. | ||
/// | ||
/// - impact: Used for calling `UIImpactFeedbackGenerator().impactOccurred()`. | ||
/// - selection: Used for calling `UISelectionFeedbackGenerator().selectionChanged()`. | ||
/// - notification: Used for calling `UINotificationFeedbackGenerator().notificationOccurred(notificationType)`. | ||
public enum HapticFeedback: HapticEmitting { | ||
|
||
fileprivate static let impactGenerator = UIImpactFeedbackGenerator() | ||
fileprivate static let selectionGenerator = UISelectionFeedbackGenerator() | ||
fileprivate static let notificationGenerator = UINotificationFeedbackGenerator() | ||
|
||
case impact | ||
case selection | ||
case notification(UINotificationFeedbackType) | ||
} | ||
|
||
extension HapticFeedback { | ||
|
||
public func prepare() { | ||
switch self { | ||
|
||
case .impact: | ||
HapticFeedback.impactGenerator.prepare() | ||
|
||
case .selection: | ||
HapticFeedback.selectionGenerator.prepare() | ||
|
||
case .notification: | ||
HapticFeedback.notificationGenerator.prepare() | ||
} | ||
} | ||
|
||
public func generateFeedback() { | ||
switch self { | ||
|
||
case .impact: | ||
HapticFeedback.impactGenerator.impactOccurred() | ||
|
||
case .selection: | ||
HapticFeedback.selectionGenerator.selectionChanged() | ||
|
||
case .notification(let notificationType): | ||
HapticFeedback.notificationGenerator.notificationOccurred(notificationType) | ||
} | ||
} | ||
} | ||
|
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,54 @@ | ||
import AudioToolbox | ||
|
||
/// A set of text message sound effects that iOS provides through the `AudioServicesPlaySystemSound` subsystem. | ||
public enum MessageTone: Int { | ||
|
||
case note = 1375 | ||
case aurora = 1366 | ||
case bamboo = 1361 | ||
case chord = 1312 | ||
case circles = 1368 | ||
case complete = 1362 | ||
case hello = 1363 | ||
case input = 1369 | ||
case keys = 1367 | ||
case popcorn = 1364 | ||
case pulse = 1120 | ||
case synth = 1365 | ||
case alert = 1005 | ||
case anticipate = 1020 | ||
case bell = 1013 | ||
case bloom = 1021 | ||
case calypso = 1022 | ||
case chime = 1008 | ||
case choochoo = 1023 | ||
case descent = 1024 | ||
case ding = 1000 | ||
case electronic = 1014 | ||
case fanfare = 1025 | ||
case glass = 1009 | ||
case horn = 1010 | ||
case ladder = 1026 | ||
case minuet = 1027 | ||
case newsflash = 1028 | ||
case noir = 1029 | ||
case sherwoodforest = 1030 | ||
case spell = 1031 | ||
case suspence = 1032 | ||
case swish = 1018 | ||
case swoosh = 1001 | ||
case telegraph = 1033 | ||
case tiptoes = 1034 | ||
case tritone = 1002 | ||
case tweet = 1016 | ||
case typewriters = 1035 | ||
case update = 1036 | ||
} | ||
|
||
extension MessageTone: SoundEmitting { | ||
|
||
public func makeSound() { | ||
AudioServicesPlaySystemSound(UInt32(self.rawValue)) | ||
} | ||
} | ||
|
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,15 @@ | ||
import AudioToolbox | ||
|
||
/// A set of sound effects that iOS provides through the `AudioServicesPlaySystemSound` subsystem. | ||
public enum SoundEffect: Int { | ||
|
||
case tap = 1104 | ||
} | ||
|
||
extension SoundEffect: SoundEmitting { | ||
|
||
public func makeSound() { | ||
AudioServicesPlaySystemSound(UInt32(self.rawValue)) | ||
} | ||
} | ||
|
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,12 @@ | ||
import AVFoundation | ||
import Foundation | ||
|
||
extension URL: SoundEmitting { | ||
|
||
public func makeSound() { | ||
FeedbackEffect.player.removeAllItems() | ||
let item = AVPlayerItem(url: self) | ||
FeedbackEffect.player.insert(item, after: nil) | ||
FeedbackEffect.player.play() | ||
} | ||
} |
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,38 @@ | ||
import AudioToolbox | ||
|
||
/// A set of vibration patterns that iOS uses through the `AudioServicesPlaySystemSound` subsystem | ||
/// to generate vibrations on devices that do not have a taptic engine. | ||
public enum VibrationFeedback { | ||
|
||
case selection | ||
case impact | ||
case notification | ||
|
||
} | ||
|
||
private extension VibrationFeedback { | ||
|
||
var audioServicesCode: UInt32 { | ||
switch self { | ||
|
||
case .selection: | ||
return 1519 | ||
|
||
case .impact: | ||
return 1520 | ||
|
||
case .notification: | ||
return 1521 | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
extension VibrationFeedback: HapticEmitting { | ||
|
||
public func generateFeedback() { | ||
AudioServicesPlaySystemSound(self.audioServicesCode) | ||
} | ||
} | ||
|