LiveActivityBGLabelWatchView.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import SwiftUI
  2. import WidgetKit
  3. struct LiveActivityBGLabelWatchView: View {
  4. var context: ActivityViewContext<LiveActivityAttributes>
  5. var glucoseColor: Color
  6. private var dateFormatter: DateFormatter {
  7. let formatter = DateFormatter()
  8. formatter.dateStyle = .none
  9. formatter.timeStyle = .short
  10. return formatter
  11. }
  12. var body: some View {
  13. HStack {
  14. Text(context.state.bg)
  15. .font(.callout)
  16. .fontWeight(.bold)
  17. .foregroundStyle(context.isStale ? .secondary : glucoseColor)
  18. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  19. if let trendArrow = context.state.direction {
  20. Text(trendArrow)
  21. .font(.callout)
  22. .fontWeight(.bold)
  23. .foregroundStyle(context.isStale ? .secondary : glucoseColor)
  24. .padding(.leading, -5)
  25. }
  26. Text(context.state.change)
  27. .font(.callout)
  28. .foregroundStyle(context.isStale ? .secondary : glucoseColor)
  29. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  30. Spacer()
  31. Text("\((context.state.date != nil) ? dateFormatter.string(from: context.state.date!) : "--")")
  32. .font(.callout)
  33. .foregroundStyle(context.isStale ? .red.opacity(0.6) : .primary)
  34. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  35. }
  36. }
  37. }