@@ -45,16 +45,23 @@ struct ActionButtonObserve: View {
45
45
// MARK: Lifecycle
46
46
47
47
init ( image: String , imageWasTapped: Binding < Bool > ) {
48
- guard let image = Bundle . path ( forImage: image) else {
49
- fatalError ( " Image not found " )
48
+ if let imagePath = Bundle . path ( forImage: image) {
49
+ self . image = imagePath
50
+ self . isSFSymbol = false
51
+ } else if UIImage ( systemName: image) != nil {
52
+ self . image = image
53
+ self . isSFSymbol = true
54
+ } else {
55
+ fatalError ( " Image not found: \( image) " )
50
56
}
51
- self . image = image
57
+
52
58
self . _imageWasTapped = imageWasTapped
53
59
}
54
60
55
61
// MARK: Internal
56
62
57
63
let image : String
64
+ let isSFSymbol : Bool
58
65
59
66
@Binding var imageWasTapped : Bool
60
67
@@ -76,28 +83,44 @@ struct ActionButtonObserve: View {
76
83
}
77
84
. disabled ( self . imageWasTapped)
78
85
. background {
79
- if !FileManager. default. fileExists ( atPath: self . image) {
80
- self . imageNotFound ( )
81
- }
82
-
83
- if self . image. isRasterImageFile {
84
- Image ( uiImage: UIImage ( named: self . image) !)
86
+ if self . isSFSymbol {
87
+ Image ( systemName: self . image)
85
88
. resizable ( )
86
89
. clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
87
90
. scaledToFit ( )
91
+ . padding ( 60 )
88
92
. frame ( width: 460 , height: 460 )
89
- . clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
90
- . modifier ( AnimatableBlur ( blurRadius: self . imageWasTapped ? 0 : 20 ) )
91
- . modifier ( AnimatableSaturation ( saturation: self . imageWasTapped ? 1 : 0 ) )
92
- }
93
-
94
- if self . image. isVectorImageFile {
95
- SVGView ( contentsOf: URL ( fileURLWithPath: self . image) )
96
- . frame ( width: 460 , height: 460 )
93
+ . foregroundStyle ( . black)
97
94
. background ( self . choiceBackgroundColor)
98
95
. clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
99
96
. modifier ( AnimatableBlur ( blurRadius: self . imageWasTapped ? 0 : 20 ) )
100
97
. modifier ( AnimatableSaturation ( saturation: self . imageWasTapped ? 1 : 0 ) )
98
+ } else {
99
+ if !FileManager. default. fileExists ( atPath: self . image) {
100
+ self . imageNotFound ( )
101
+ }
102
+
103
+ if self . image. isRasterImageFile {
104
+ Image ( uiImage: UIImage ( named: self . image) !)
105
+ . resizable ( )
106
+ . clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
107
+ . scaledToFit ( )
108
+ . frame ( width: 460 , height: 460 )
109
+ . background ( self . choiceBackgroundColor)
110
+ . clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
111
+ . modifier ( AnimatableBlur ( blurRadius: self . imageWasTapped ? 0 : 20 ) )
112
+ . modifier ( AnimatableSaturation ( saturation: self . imageWasTapped ? 1 : 0 ) )
113
+ }
114
+
115
+ if self . image. isVectorImageFile {
116
+ SVGView ( contentsOf: URL ( fileURLWithPath: self . image) )
117
+ . clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
118
+ . frame ( width: 460 , height: 460 )
119
+ . background ( self . choiceBackgroundColor)
120
+ . clipShape ( RoundedRectangle ( cornerRadius: 10 ) )
121
+ . modifier ( AnimatableBlur ( blurRadius: self . imageWasTapped ? 0 : 20 ) )
122
+ . modifier ( AnimatableSaturation ( saturation: self . imageWasTapped ? 1 : 0 ) )
123
+ }
101
124
}
102
125
}
103
126
}
@@ -144,14 +167,24 @@ extension l10n {
144
167
}
145
168
146
169
#Preview {
147
- struct ActionObserveButtonContainer : View {
148
- @State var imageWasTapped = false
149
- var body : some View {
150
- ActionButtonObserve (
151
- image: " placeholder-observe_then_touch_to_select " , imageWasTapped: $imageWasTapped
152
- )
170
+ ScrollView {
171
+ VStack {
172
+ HStack {
173
+ ActionButtonObserve (
174
+ image: " 4.circle " , imageWasTapped: . constant( false )
175
+ )
176
+ ActionButtonObserve (
177
+ image: " 4.circle " , imageWasTapped: . constant( true )
178
+ )
179
+ }
180
+ HStack {
181
+ ActionButtonObserve (
182
+ image: " pictograms-foods-fruits-banana_yellow-00FB " , imageWasTapped: . constant( false )
183
+ )
184
+ ActionButtonObserve (
185
+ image: " pictograms-foods-fruits-banana_yellow-00FB " , imageWasTapped: . constant( true )
186
+ )
187
+ }
153
188
}
154
189
}
155
-
156
- return ActionObserveButtonContainer ( )
157
190
}
0 commit comments