LiveActivityUpdatedLabelView.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // LiveActivityUpdatedLabelView.swift
  3. // FreeAPS
  4. //
  5. // Created by Cengiz Deniz on 17.10.24.
  6. //
  7. import Foundation
  8. import SwiftUI
  9. import WidgetKit
  10. struct LiveActivityUpdatedLabelView: View {
  11. var context: ActivityViewContext<LiveActivityAttributes>
  12. var isDetailedLayout: Bool
  13. private var dateFormatter: DateFormatter {
  14. let formatter = DateFormatter()
  15. formatter.dateStyle = .none
  16. formatter.timeStyle = .short
  17. return formatter
  18. }
  19. var body: some View {
  20. let dateText = Text("\((context.state.date != nil) ? dateFormatter.string(from: context.state.date!) : "--")")
  21. if isDetailedLayout {
  22. VStack {
  23. dateText
  24. .font(.title3)
  25. .bold()
  26. .foregroundStyle(context.isStale ? .red.opacity(0.6) : .primary)
  27. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  28. Text("Updated").font(.subheadline).foregroundStyle(.primary)
  29. }
  30. } else {
  31. HStack {
  32. Text("Updated:").font(.subheadline).foregroundStyle(.secondary)
  33. dateText
  34. .font(.subheadline)
  35. .bold()
  36. .foregroundStyle(context.isStale ? .red.opacity(0.6) : .secondary)
  37. .strikethrough(context.isStale, pattern: .solid, color: .red.opacity(0.6))
  38. }
  39. }
  40. }
  41. }