LiveActivityBGLabelWatchView.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. .foregroundStyle(context.isStale ? .secondary : glucoseColor)
  17. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  18. if let trendArrow = context.state.direction {
  19. Text(trendArrow)
  20. .font(.callout)
  21. .foregroundStyle(context.isStale ? .secondary : glucoseColor)
  22. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  23. .padding(.leading, -5)
  24. }
  25. Text(context.state.change)
  26. .font(.callout)
  27. .foregroundStyle(.primary)
  28. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  29. Spacer()
  30. Text("\((context.state.date != nil) ? dateFormatter.string(from: context.state.date!) : "--")")
  31. .font(.callout)
  32. .foregroundStyle(context.isStale ? .red.opacity(0.6) : .primary)
  33. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  34. }
  35. }
  36. }