@@ -119,13 +119,13 @@ extension String: Identifiable {
119
119
}
120
120
}
121
121
122
- struct PluginMenuItem : Identifiable {
122
+ struct PluginMenuItem < Content : View > : Identifiable {
123
123
var id : String {
124
124
return pluginIdentifier + String( describing: offset)
125
125
}
126
126
127
127
let section : SettingsMenuSection
128
- let view : AnyView
128
+ let view : Content
129
129
let pluginIdentifier : String
130
130
let offset : Int
131
131
}
@@ -206,7 +206,7 @@ extension SettingsView {
206
206
Section ( header: SectionHeader ( label: NSLocalizedString ( " Configuration " , comment: " The title of the Configuration section in settings " ) ) ) {
207
207
LargeButton ( action: { self . therapySettingsIsPresented = true } ,
208
208
includeArrow: true ,
209
- imageView: AnyView ( Image ( " Therapy Icon " ) ) ,
209
+ imageView: Image ( " Therapy Icon " ) ,
210
210
label: NSLocalizedString ( " Therapy Settings " , comment: " Title text for button to Therapy Settings " ) ,
211
211
descriptiveText: NSLocalizedString ( " Diabetes Treatment " , comment: " Descriptive text for Therapy Settings " ) )
212
212
. sheet ( isPresented: $therapySettingsIsPresented) {
@@ -235,7 +235,7 @@ extension SettingsView {
235
235
}
236
236
}
237
237
238
- private var pluginMenuItems : [ PluginMenuItem ] {
238
+ private var pluginMenuItems : [ PluginMenuItem < some View > ] {
239
239
self . viewModel. availableSupports. flatMap { plugin in
240
240
plugin. configurationMenuItems ( ) . enumerated ( ) . map { index, item in
241
241
PluginMenuItem ( section: item. section, view: item. view, pluginIdentifier: plugin. identifier, offset: index)
@@ -261,7 +261,7 @@ extension SettingsView {
261
261
} else if viewModel. isOnboardingComplete {
262
262
LargeButton ( action: { self . pumpChooserIsPresented = true } ,
263
263
includeArrow: false ,
264
- imageView: AnyView ( plusImage) ,
264
+ imageView: plusImage,
265
265
label: NSLocalizedString ( " Add Pump " , comment: " Title text for button to add pump device " ) ,
266
266
descriptiveText: NSLocalizedString ( " Tap here to set up a pump " , comment: " Descriptive text for button to add pump device " ) )
267
267
. actionSheet ( isPresented: $pumpChooserIsPresented) {
@@ -293,7 +293,7 @@ extension SettingsView {
293
293
} else {
294
294
LargeButton ( action: { self . cgmChooserIsPresented = true } ,
295
295
includeArrow: false ,
296
- imageView: AnyView ( plusImage) ,
296
+ imageView: plusImage,
297
297
label: NSLocalizedString ( " Add CGM " , comment: " Title text for button to add CGM device " ) ,
298
298
descriptiveText: NSLocalizedString ( " Tap here to set up a CGM " , comment: " Descriptive text for button to add CGM device " ) )
299
299
. actionSheet ( isPresented: $cgmChooserIsPresented) {
@@ -306,7 +306,7 @@ extension SettingsView {
306
306
Section {
307
307
LargeButton ( action: { self . favoriteFoodsIsPresented = true } ,
308
308
includeArrow: true ,
309
- imageView: AnyView ( Image ( " Favorite Foods Icon " ) . renderingMode ( . template) . foregroundColor ( carbTintColor) ) ,
309
+ imageView: Image ( " Favorite Foods Icon " ) . renderingMode ( . template) . foregroundColor ( carbTintColor) ,
310
310
label: " Favorite Foods " ,
311
311
descriptiveText: " Simplify Carb Entry " )
312
312
}
@@ -339,7 +339,7 @@ extension SettingsView {
339
339
if viewModel. servicesViewModel. inactiveServices ( ) . count > 0 {
340
340
LargeButton ( action: { self . serviceChooserIsPresented = true } ,
341
341
includeArrow: false ,
342
- imageView: AnyView ( plusImage) ,
342
+ imageView: plusImage,
343
343
label: NSLocalizedString ( " Add Service " , comment: " The title of the add service button in settings " ) ,
344
344
descriptiveText: NSLocalizedString ( " Tap here to set up a Service " , comment: " The descriptive text of the add service button in settings " ) )
345
345
. actionSheet ( isPresented: $serviceChooserIsPresented) {
@@ -455,41 +455,43 @@ extension SettingsView {
455
455
. padding ( EdgeInsets ( top: 10 , leading: 10 , bottom: 10 , trailing: 10 ) )
456
456
}
457
457
458
- private func deviceImage( uiImage: UIImage ? ) -> AnyView {
458
+ @ViewBuilder
459
+ private func deviceImage( uiImage: UIImage ? ) -> some View {
459
460
if let uiImage = uiImage {
460
- return AnyView ( Image ( uiImage: uiImage)
461
+ Image ( uiImage: uiImage)
461
462
. renderingMode ( . original)
462
463
. resizable ( )
463
- . scaledToFit ( ) )
464
+ . scaledToFit ( )
464
465
} else {
465
- return AnyView ( Spacer ( ) )
466
+ Spacer ( )
466
467
}
467
468
}
468
469
469
- private func serviceImage( uiImage: UIImage ? ) -> AnyView {
470
- return deviceImage ( uiImage: uiImage)
470
+ @ViewBuilder
471
+ private func serviceImage( uiImage: UIImage ? ) -> some View {
472
+ deviceImage ( uiImage: uiImage)
471
473
}
472
474
}
473
475
474
- fileprivate struct LargeButton : View {
476
+ fileprivate struct LargeButton < Content : View > : View {
475
477
476
478
let action : ( ) -> Void
477
479
var includeArrow : Bool = true
478
- let imageView : AnyView
480
+ let imageView : Content
479
481
let label : String
480
482
let descriptiveText : String
481
483
482
484
// TODO: The design doesn't show this, but do we need to consider different values here for different size classes?
483
- static let spacing : CGFloat = 15
484
- static let imageWidth : CGFloat = 60
485
- static let imageHeight : CGFloat = 60
486
- static let topBottomPadding : CGFloat = 10
485
+ private let spacing : CGFloat = 15
486
+ private let imageWidth : CGFloat = 60
487
+ private let imageHeight : CGFloat = 60
488
+ private let topBottomPadding : CGFloat = 10
487
489
488
490
public var body : some View {
489
491
Button ( action: action) {
490
492
HStack {
491
- HStack ( spacing: Self . spacing) {
492
- imageView. frame ( width: Self . imageWidth, height: Self . imageHeight)
493
+ HStack ( spacing: spacing) {
494
+ imageView. frame ( width: imageWidth, height: imageHeight)
493
495
VStack ( alignment: . leading) {
494
496
Text ( label)
495
497
. foregroundColor ( . primary)
@@ -502,7 +504,7 @@ fileprivate struct LargeButton: View {
502
504
Image ( systemName: " chevron.right " ) . foregroundColor ( . gray) . font ( . footnote)
503
505
}
504
506
}
505
- . padding ( EdgeInsets ( top: Self . topBottomPadding, leading: 0 , bottom: Self . topBottomPadding, trailing: 0 ) )
507
+ . padding ( EdgeInsets ( top: topBottomPadding, leading: 0 , bottom: topBottomPadding, trailing: 0 ) )
506
508
}
507
509
}
508
510
}
0 commit comments