diff --git a/LoopKitUI/Views/CheckmarkListItem.swift b/LoopKitUI/Views/CheckmarkListItem.swift index a34175296..3d8857fd4 100644 --- a/LoopKitUI/Views/CheckmarkListItem.swift +++ b/LoopKitUI/Views/CheckmarkListItem.swift @@ -8,20 +8,44 @@ import SwiftUI -public struct CheckmarkListItem: View { +public struct CheckmarkListItem: View { var title: Text var titleFont: Font var description: Text @Binding var isSelected: Bool let isEnabled: Bool + let leadingView: LeadingView? - public init(title: Text, titleFont: Font = .headline, description: Text, isSelected: Binding, isEnabled: Bool = true) { + public init( + title: Text, + titleFont: Font = .headline, + description: Text, + isSelected: Binding, + isEnabled: Bool = true, + @ViewBuilder leadingView: () -> LeadingView + ) { self.title = title self.titleFont = titleFont self.description = description self._isSelected = isSelected self.isEnabled = isEnabled + self.leadingView = leadingView() + } + + public init( + title: Text, + titleFont: Font = .headline, + description: Text, + isSelected: Binding, + isEnabled: Bool = true + ) where LeadingView == EmptyView { + self.title = title + self.titleFont = titleFont + self.description = description + self._isSelected = isSelected + self.isEnabled = isEnabled + self.leadingView = nil } @ViewBuilder @@ -37,6 +61,10 @@ public struct CheckmarkListItem: View { private var content: some View { HStack(spacing: 0) { + if let leadingView = leadingView { + leadingView + } + VStack(alignment: .leading, spacing: 4) { title .font(titleFont) diff --git a/LoopKitUI/Views/InsulinTypeChooser.swift b/LoopKitUI/Views/InsulinTypeChooser.swift index 11c44f365..3a3163896 100644 --- a/LoopKitUI/Views/InsulinTypeChooser.swift +++ b/LoopKitUI/Views/InsulinTypeChooser.swift @@ -28,7 +28,20 @@ public struct InsulinTypeChooser: View { public var body: some View { ForEach(supportedInsulinTypes, id: \.self) { insulinType in if let insulinType = insulinType { - HStack { + CheckmarkListItem( + title: Text(insulinType.title), + description: Text(insulinType.description), + isSelected: Binding( + get: { self.insulinType == insulinType }, + set: { isSelected in + if isSelected { + withAnimation { + self.insulinType = insulinType + } + } + } + ) + ) { ZStack { Image(frameworkImage: "vial_color") .renderingMode(.template) @@ -41,38 +54,22 @@ public struct InsulinTypeChooser: View { } .padding([.trailing]) .frame(height: 70) - CheckmarkListItem( - title: Text(insulinType.title), - description: Text(insulinType.description), - isSelected: Binding( - get: { self.insulinType == insulinType }, - set: { isSelected in - if isSelected { - withAnimation { - self.insulinType = insulinType - } - } - } - ) - ) } } else { - HStack { - CheckmarkListItem( - title: Text(LocalizedString("Unset", comment: "Title for selection when no insulin type is selected.")), - description: Text(LocalizedString("The currently selected fast acting insulin model will be used as a default.", comment: "Description for selection when no insulin type is selected.")), - isSelected: Binding( - get: { self.insulinType == nil }, - set: { isSelected in - if isSelected { - withAnimation { - self.insulinType = nil - } + CheckmarkListItem( + title: Text(LocalizedString("Unset", comment: "Title for selection when no insulin type is selected.")), + description: Text(LocalizedString("The currently selected fast acting insulin model will be used as a default.", comment: "Description for selection when no insulin type is selected.")), + isSelected: Binding( + get: { self.insulinType == nil }, + set: { isSelected in + if isSelected { + withAnimation { + self.insulinType = nil } } - ) + } ) - } + ) } } }