Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions LoopKitUI/Views/CheckmarkListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,44 @@

import SwiftUI

public struct CheckmarkListItem: View {
public struct CheckmarkListItem<LeadingView: View>: 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<Bool>, isEnabled: Bool = true) {
public init(
title: Text,
titleFont: Font = .headline,
description: Text,
isSelected: Binding<Bool>,
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<Bool>,
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
Expand All @@ -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)
Expand Down
53 changes: 25 additions & 28 deletions LoopKitUI/Views/InsulinTypeChooser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
)
}
)
}
)
}
}
}
Expand Down