-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathBasalViewActivity.swift
More file actions
50 lines (44 loc) · 1.39 KB
/
BasalViewActivity.swift
File metadata and controls
50 lines (44 loc) · 1.39 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
//
// BasalView.swift
// Loop
//
// Created by Noah Brauner on 8/15/22.
// Copyright © 2022 LoopKit Authors. All rights reserved.
//
import SwiftUI
struct BasalViewActivity: View {
let percent: Double
let rate: Double
var body: some View {
VStack(spacing: 1) {
BasalRateView(percent: percent)
.overlay(
BasalRateView(percent: percent)
.stroke(Color("insulin"), lineWidth: 2)
)
.foregroundColor(Color("insulin").opacity(0.5))
.frame(width: 44, height: 22)
if let rateString = decimalFormatter.string(from: NSNumber(value: rate)) {
Text("\(rateString)U")
.font(.subheadline)
.minimumScaleFactor(0.5)
.lineLimit(2)
}
else {
Text("-U")
.font(.subheadline)
.minimumScaleFactor(0.5)
.lineLimit(2)
}
}
}
private let decimalFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.minimumFractionDigits = 1
formatter.minimumIntegerDigits = 1
formatter.positiveFormat = "+0.0##"
formatter.negativeFormat = "-0.0##"
return formatter
}()
}