@@ -124,98 +124,98 @@ struct BaseWidget<Content: View>: View {
124124 }
125125
126126 var body : some View {
127- Button { } label: {
128- VStack ( spacing: 0 ) {
129- if isEditing {
130- HStack {
131- HStack ( spacing: 16 ) {
132- Image ( metadata. icon)
133- . resizable ( )
134- . frame ( width: 32 , height: 32 )
127+ widgetContent
128+ . accessibilityIdentifierIfPresent ( isEditing ? nil : " \( type. rawValue. capitalized) Widget " )
129+ . frame ( maxWidth: . infinity)
130+ . padding ( ( hasBackground || isEditing) ? 16 : 0 )
131+ . background ( ( hasBackground || isEditing) ? Color . gray6 : Color . clear)
132+ . cornerRadius ( hasBackground || isEditing ? 16 : 0 )
133+ . alert (
134+ t ( " widgets__delete__title " ) ,
135+ isPresented: $showDeleteDialog,
136+ actions: {
137+ Button ( t ( " common__cancel " ) , role: . cancel) {
138+ showDeleteDialog = false
139+ }
135140
136- BodyMSBText ( truncate ( metadata. name, 18 ) )
137- . lineLimit ( 1 )
138- }
141+ Button ( t ( " common__delete_yes " ) , role: . destructive) {
142+ widgets. deleteWidget ( type)
143+ showDeleteDialog = false
144+ }
145+ } ,
146+ message: {
147+ Text ( t ( " widgets__delete__description " , variables: [ " name " : metadata. name] ) )
148+ }
149+ )
150+ }
139151
140- Spacer ( )
141-
142- // Action buttons when in edit mode
143- if isEditing {
144- HStack ( spacing: 8 ) {
145- // Delete button
146- Button {
147- onDelete ( )
148- } label: {
149- Image ( " trash " )
150- . resizable ( )
151- . foregroundColor ( . textPrimary)
152- . frame ( width: 24 , height: 24 )
153- }
154- . frame ( width: 32 , height: 32 )
155- . contentShape ( Rectangle ( ) )
156- . accessibilityIdentifier ( " \( metadata. name) _WidgetActionDelete " )
157-
158- // Edit button
159- Button {
160- onEdit ( )
161- } label: {
162- Image ( " gear-six " )
163- . resizable ( )
164- . foregroundColor ( . textPrimary)
165- . frame ( width: 24 , height: 24 )
166- }
167- . frame ( width: 32 , height: 32 )
168- . contentShape ( Rectangle ( ) )
169- . accessibilityIdentifier ( " \( metadata. name) _WidgetActionEdit " )
152+ private var widgetContent : some View {
153+ VStack ( spacing: 0 ) {
154+ if isEditing {
155+ HStack {
156+ HStack ( spacing: 16 ) {
157+ Image ( metadata. icon)
158+ . resizable ( )
159+ . frame ( width: 32 , height: 32 )
160+
161+ BodyMSBText ( truncate ( metadata. name, 18 ) )
162+ . lineLimit ( 1 )
163+ }
164+
165+ Spacer ( )
170166
171- Image ( " burger " )
167+ // Action buttons when in edit mode
168+ if isEditing {
169+ HStack ( spacing: 8 ) {
170+ // Delete button
171+ Button {
172+ onDelete ( )
173+ } label: {
174+ Image ( " trash " )
172175 . resizable ( )
173176 . foregroundColor ( . textPrimary)
174177 . frame ( width: 24 , height: 24 )
175- . frame ( width: 32 , height: 32 )
176- . contentShape ( Rectangle ( ) )
177- . overlay {
178- Color . clear
179- . frame ( width: 44 , height: 44 )
180- . contentShape ( Rectangle ( ) )
181- . trackDragHandle ( )
182- }
183- . accessibilityIdentifier ( " \( metadata. name) _WidgetActionReorder " )
184178 }
179+ . frame ( width: 32 , height: 32 )
180+ . contentShape ( Rectangle ( ) )
181+ . accessibilityIdentifier ( " \( metadata. name) _WidgetActionDelete " )
182+
183+ // Edit button
184+ Button {
185+ onEdit ( )
186+ } label: {
187+ Image ( " gear-six " )
188+ . resizable ( )
189+ . foregroundColor ( . textPrimary)
190+ . frame ( width: 24 , height: 24 )
191+ }
192+ . frame ( width: 32 , height: 32 )
193+ . contentShape ( Rectangle ( ) )
194+ . accessibilityIdentifier ( " \( metadata. name) _WidgetActionEdit " )
195+
196+ Image ( " burger " )
197+ . resizable ( )
198+ . foregroundColor ( . textPrimary)
199+ . frame ( width: 24 , height: 24 )
200+ . frame ( width: 32 , height: 32 )
201+ . contentShape ( Rectangle ( ) )
202+ . overlay {
203+ Color . clear
204+ . frame ( width: 44 , height: 44 )
205+ . contentShape ( Rectangle ( ) )
206+ . trackDragHandle ( )
207+ }
208+ . accessibilityIdentifier ( " \( metadata. name) _WidgetActionReorder " )
185209 }
186210 }
187211 }
188-
189- // Widget content (only shown when not editing)
190- if !isEditing {
191- content
192- }
193212 }
194- . contentShape ( Rectangle ( ) )
195- }
196- . accessibilityIdentifier ( " \( type. rawValue. capitalized) Widget " )
197- . buttonStyle ( WidgetButtonStyle ( ) )
198- . frame ( maxWidth: . infinity)
199- . padding ( ( hasBackground || isEditing) ? 16 : 0 )
200- . background ( ( hasBackground || isEditing) ? Color . gray6 : Color . clear)
201- . cornerRadius ( hasBackground || isEditing ? 16 : 0 )
202- . alert (
203- t ( " widgets__delete__title " ) ,
204- isPresented: $showDeleteDialog,
205- actions: {
206- Button ( t ( " common__cancel " ) , role: . cancel) {
207- showDeleteDialog = false
208- }
209213
210- Button ( t ( " common__delete_yes " ) , role: . destructive) {
211- widgets. deleteWidget ( type)
212- showDeleteDialog = false
213- }
214- } ,
215- message: {
216- Text ( t ( " widgets__delete__description " , variables: [ " name " : metadata. name] ) )
214+ // Widget content (only shown when not editing)
215+ if !isEditing {
216+ content
217217 }
218- )
218+ }
219219 }
220220
221221 /// Truncate a string to a maximum length
@@ -229,14 +229,6 @@ struct BaseWidget<Content: View>: View {
229229 }
230230}
231231
232- /// Custom button style for widgets
233- struct WidgetButtonStyle : ButtonStyle {
234- func makeBody( configuration: Configuration ) -> some View {
235- configuration. label
236- . opacity ( configuration. isPressed ? 0.9 : 1.0 )
237- }
238- }
239-
240232// Preview for the BaseWidget
241233#Preview {
242234 VStack {
@@ -269,6 +261,5 @@ struct WidgetButtonStyle: ButtonStyle {
269261 . environmentObject ( WidgetsViewModel ( ) )
270262 . environmentObject ( NavigationViewModel ( ) )
271263 . environmentObject ( CurrencyViewModel ( ) )
272- . environmentObject ( SettingsViewModel . shared)
273264 . preferredColorScheme ( . dark)
274265}
0 commit comments