-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFeedbackStyle.swift
115 lines (101 loc) · 2.67 KB
/
FeedbackStyle.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// FeedbackStyle.swift
//
// Made with ❤️ by Novum
//
// Copyright © Telefonica. All rights reserved.
//
import Foundation
import SwiftUI
enum FeedbackIconStyle {
case none
case image(Image)
case animation(LottieView)
}
public enum FeedbackStyle {
case success
case error(reference: String?)
case informative
case feedback(Image)
var shouldUseInverseFeedbacks: Bool {
switch self {
case .success:
return true
case .informative, .error, .feedback:
return false
}
}
var primaryButtonStyle: MisticaButtonStyle {
shouldUseInverseFeedbacks ? .misticaPrimaryInverse() : .misticaPrimary()
}
var secondaryButtonStyle: MisticaButtonStyle {
shouldUseInverseFeedbacks ? .misticaSecondaryInverse() : .misticaSecondary()
}
var linkButtonStyle: MisticaButtonStyle {
shouldUseInverseFeedbacks ? .misticaLinkInverse() : .misticaLink()
}
var iconStyle: FeedbackIconStyle {
switch self {
case .success, .error:
guard let dataAsset = dataAsset else { return .none }
return .animation(LottieView(loopMode: .playOnce, asset: dataAsset, scaleToFit: true))
case .informative:
guard let image = image else { return .none }
return .image(image)
case .feedback(let image):
return .image(image)
}
}
private var dataAsset: NSDataAsset? {
switch self {
case .success:
return .successAnimation
case .error:
return .errorAnimation
case .informative, .feedback:
return nil
}
}
private var image: Image? {
switch self {
case .success, .error:
return nil
case .informative:
return Image.iconNotificationInfo
case .feedback(let image):
return image
}
}
var hapticFeedbackStyle: UINotificationFeedbackGenerator.FeedbackType? {
switch self {
case .success:
return .success
case .informative:
return .warning
case .error:
return .error
case .feedback:
return nil
}
}
var hapticFeedbackDelay: TimeInterval? {
switch self {
case .success:
return 0.45
case .informative:
return 0
case .error:
return 0.5
case .feedback:
return nil
}
}
var shouldAnimate: Bool {
switch self {
case .success, .error:
return true
case .informative, .feedback:
return false
}
}
}