LiveActivityUpdatedLabelView.swift 1.7 KB

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