@@ -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) {
@@ -481,41 +481,43 @@ extension SettingsView {
481
481
. padding ( EdgeInsets ( top: 10 , leading: 10 , bottom: 10 , trailing: 10 ) )
482
482
}
483
483
484
- private func deviceImage( uiImage: UIImage ? ) -> AnyView {
484
+ @ViewBuilder
485
+ private func deviceImage( uiImage: UIImage ? ) -> some View {
485
486
if let uiImage = uiImage {
486
- return AnyView ( Image ( uiImage: uiImage)
487
+ Image ( uiImage: uiImage)
487
488
. renderingMode ( . original)
488
489
. resizable ( )
489
- . scaledToFit ( ) )
490
+ . scaledToFit ( )
490
491
} else {
491
- return AnyView ( Spacer ( ) )
492
+ Spacer ( )
492
493
}
493
494
}
494
495
495
- private func serviceImage( uiImage: UIImage ? ) -> AnyView {
496
- return deviceImage ( uiImage: uiImage)
496
+ @ViewBuilder
497
+ private func serviceImage( uiImage: UIImage ? ) -> some View {
498
+ deviceImage ( uiImage: uiImage)
497
499
}
498
500
}
499
501
500
- fileprivate struct LargeButton : View {
502
+ fileprivate struct LargeButton < Content : View > : View {
501
503
502
504
let action : ( ) -> Void
503
505
var includeArrow : Bool = true
504
- let imageView : AnyView
506
+ let imageView : Content
505
507
let label : String
506
508
let descriptiveText : String
507
509
508
510
// TODO: The design doesn't show this, but do we need to consider different values here for different size classes?
509
- static let spacing : CGFloat = 15
510
- static let imageWidth : CGFloat = 60
511
- static let imageHeight : CGFloat = 60
512
- static let topBottomPadding : CGFloat = 10
511
+ private let spacing : CGFloat = 15
512
+ private let imageWidth : CGFloat = 60
513
+ private let imageHeight : CGFloat = 60
514
+ private let topBottomPadding : CGFloat = 10
513
515
514
516
public var body : some View {
515
517
Button ( action: action) {
516
518
HStack {
517
- HStack ( spacing: Self . spacing) {
518
- imageView. frame ( width: Self . imageWidth, height: Self . imageHeight)
519
+ HStack ( spacing: spacing) {
520
+ imageView. frame ( width: imageWidth, height: imageHeight)
519
521
VStack ( alignment: . leading) {
520
522
Text ( label)
521
523
. foregroundColor ( . primary)
@@ -528,7 +530,7 @@ fileprivate struct LargeButton: View {
528
530
Image ( systemName: " chevron.right " ) . foregroundColor ( . gray) . font ( . footnote)
529
531
}
530
532
}
531
- . padding ( EdgeInsets ( top: Self . topBottomPadding, leading: 0 , bottom: Self . topBottomPadding, trailing: 0 ) )
533
+ . padding ( EdgeInsets ( top: topBottomPadding, leading: 0 , bottom: topBottomPadding, trailing: 0 ) )
532
534
}
533
535
}
534
536
}
0 commit comments