GlucoseInformationBarView.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import SwiftUI
  2. public struct GlucoseInformationBarView: View {
  3. let data: [InformationBarEntryData]
  4. let glucoseValue: Double
  5. let glucoseDelta: Double
  6. public init(data: [InformationBarEntryData], glucoseValue: Double, glucoseDelta: Double) {
  7. self.data = data
  8. self.glucoseValue = glucoseValue
  9. self.glucoseDelta = glucoseDelta
  10. }
  11. public var body: some View {
  12. let halvedEntryData = data.halve()
  13. HStack {
  14. VStack {
  15. ForEach(halvedEntryData, id: \.self) { half in
  16. HStack {
  17. ForEach(half, id: \.self) { dataEntry in
  18. Text(
  19. dataEntry.label + "\n" +
  20. APSDataFormatter.format(
  21. inputValue: dataEntry.value,
  22. to: dataEntry.type
  23. )
  24. )
  25. .font(.footnote)
  26. .informationBarEntryStyle()
  27. .padding(.bottom, 1)
  28. }
  29. }
  30. }
  31. }
  32. Text(APSDataFormatter.format(inputValue: glucoseValue, to: .glucose))
  33. .font(.largeTitle)
  34. .foregroundColor(Color(.systemBlue))
  35. .informationBarEntryStyle()
  36. VStack {
  37. GlucoseArrowView(value: glucoseValue, delta: glucoseDelta)
  38. .padding(.bottom, 1)
  39. Text(APSDataFormatter.format(inputValue: glucoseDelta, to: .delta))
  40. .informationBarEntryStyle()
  41. .padding(.bottom, 1)
  42. }
  43. }
  44. .padding(.bottom, -1)
  45. }
  46. }
  47. struct GlucoseInformationBarView_Previews: PreviewProvider {
  48. static let data = [
  49. InformationBarEntryData(label: "COB: ", type: .cob, value: 33),
  50. InformationBarEntryData(label: "COB: ", type: .cob, value: 33),
  51. InformationBarEntryData(label: "COB: ", type: .cob, value: 33),
  52. InformationBarEntryData(label: "COB: ", type: .cob, value: 33),
  53. InformationBarEntryData(label: "COB: ", type: .cob, value: 33)
  54. ]
  55. static var previews: some View {
  56. GlucoseInformationBarView(data: data, glucoseValue: 5.5, glucoseDelta: -0.2)
  57. .preferredColorScheme(.dark)
  58. .frame(height: 200)
  59. }
  60. }