-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathExpirationReminderPickerView.swift
More file actions
71 lines (60 loc) · 2.15 KB
/
ExpirationReminderPickerView.swift
File metadata and controls
71 lines (60 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// ExpirationReminderPickerView.swift
// OmniKit
//
// Created by Pete Schwamb on 5/17/21.
// Copyright © 2021 LoopKit Authors. All rights reserved.
//
import SwiftUI
import LoopKit
import LoopKitUI
import HealthKit
struct ExpirationReminderPickerView: View {
static let expirationReminderHoursAllowed = 0...24
var expirationReminderDefault: Binding<Int>
var collapsible: Bool = true
@State var showingHourPicker: Bool = false
var expirationDefaultFormatter = QuantityFormatter(for: .hour())
var expirationDefaultString: String {
return expirationReminderHourString(expirationReminderDefault.wrappedValue)
}
var body: some View {
VStack {
HStack {
Text(LocalizedString("Expiration Reminder Default", comment: "Label text for expiration reminder default row"))
Spacer()
if collapsible {
Button(expirationDefaultString) {
withAnimation {
showingHourPicker.toggle()
}
}
} else {
Text(expirationDefaultString)
}
}
if showingHourPicker {
Picker(selection: expirationReminderDefault) {
ForEach(Array(Self.expirationReminderHoursAllowed), id: \.self) { value in
Text(expirationReminderHourString(value))
}
} label: {
EmptyView()
}
.pickerStyle(.wheel)
}
}
}
private func expirationReminderHourString(_ value: Int) -> String {
if value > 0 {
return expirationDefaultFormatter.string(from: HKQuantity(unit: .hour(), doubleValue: Double(value)))!
} else {
return LocalizedString("No Reminder", comment: "Value text for no expiration reminder")
}
}
}
struct ExpirationReminderPickerView_Previews: PreviewProvider {
static var previews: some View {
ExpirationReminderPickerView(expirationReminderDefault: .constant(2))
}
}