SnoozerView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // SnoozerView.swift
  3. // LoopFollow
  4. //
  5. // Created by Jonas Björkert on 2025-04-26.
  6. // Copyright © 2025 Jon Fawcett. All rights reserved.
  7. //
  8. import SwiftUI
  9. struct SnoozerView: View {
  10. @StateObject private var vm = SnoozerViewModel()
  11. @ObservedObject var minAgoText = Observable.shared.minAgoText
  12. @ObservedObject var bgText = Observable.shared.bgText
  13. @ObservedObject var bgTextColor = Observable.shared.bgTextColor
  14. @ObservedObject var directionText = Observable.shared.directionText
  15. @ObservedObject var deltaText = Observable.shared.deltaText
  16. @ObservedObject var bgStale = Observable.shared.bgStale
  17. var body: some View {
  18. GeometryReader { geo in
  19. Color.black.ignoresSafeArea()
  20. .overlay(contentColumn(size: geo.size))
  21. .animation(.easeInOut, value: vm.activeAlarm != nil)
  22. }
  23. }
  24. // MARK: – Layout helper
  25. @ViewBuilder private func contentColumn(size: CGSize) -> some View {
  26. if size.width > size.height { // landscape
  27. HStack(spacing: 0) { leftPanel ; rightPanel }
  28. } else { // portrait
  29. VStack(spacing: 0) { leftPanel ; rightPanel }
  30. }
  31. }
  32. // MARK: - Left Column (BG / Direction / Delta / Age)
  33. private var leftPanel: some View {
  34. VStack(spacing: 0) {
  35. Text(bgText.value)
  36. .font(.system(size: 220, weight: .black))
  37. .minimumScaleFactor(0.5)
  38. .foregroundColor(bgTextColor.value)
  39. .strikethrough(
  40. bgStale.value,
  41. pattern: .solid,
  42. color: bgStale.value ? .red : .clear
  43. )
  44. .frame(maxWidth: .infinity, maxHeight: 167)
  45. Text(directionText.value)
  46. .font(.system(size: 110, weight: .black))
  47. .minimumScaleFactor(0.5)
  48. .foregroundColor(.white)
  49. .frame(maxWidth: .infinity, maxHeight: 96)
  50. Text(deltaText.value)
  51. .font(.system(size: 70))
  52. .minimumScaleFactor(0.5)
  53. .foregroundColor(.white.opacity(0.8))
  54. .frame(maxWidth: .infinity, maxHeight: 78)
  55. Text(minAgoText.value)
  56. .font(.system(size: 70))
  57. .minimumScaleFactor(0.5)
  58. .foregroundColor(.white.opacity(0.6))
  59. .frame(maxWidth: .infinity, maxHeight: 48)
  60. }
  61. .padding(.top, 16)
  62. .padding(.horizontal, 16)
  63. }
  64. // MARK: – Right (Clock + Snooze)
  65. private var rightPanel: some View {
  66. VStack(spacing: 0) {
  67. Spacer()
  68. TimelineView(.periodic(from: .now, by: 1)) { ctx in
  69. Text(ctx.date, style: .time)
  70. .font(.system(size: 70, weight: .regular))
  71. .foregroundColor(.white)
  72. }
  73. .frame(height: 80)
  74. if let alarm = vm.activeAlarm {
  75. Text(alarm.name)
  76. .font(.system(size: 40, weight: .semibold))
  77. .foregroundColor(.red)
  78. .minimumScaleFactor(0.5)
  79. .padding(.top, 4)
  80. Spacer(minLength: 32)
  81. snoozeControls(alarm: alarm)
  82. }
  83. Spacer()
  84. }
  85. .padding(.horizontal, 24)
  86. }
  87. // MARK: – Snooze UI
  88. @ViewBuilder private func snoozeControls(alarm: Alarm) -> some View {
  89. VStack(spacing: 16) {
  90. HStack {
  91. Text("Snooze for")
  92. Spacer()
  93. Text("\(vm.snoozeMins) \(vm.timeUnitLabel)")
  94. }
  95. .font(.title3)
  96. .foregroundColor(.white)
  97. Stepper("", value: $vm.snoozeMins,
  98. in: 1...120,
  99. step: alarm.type.timeUnit == .minute ? 5 : 1)
  100. .labelsHidden()
  101. Button(action: vm.snoozeTapped) {
  102. Text("Snooze")
  103. .bold()
  104. .frame(maxWidth: .infinity, minHeight: 50)
  105. .background(Color.white.opacity(0.15))
  106. .cornerRadius(10)
  107. }
  108. }
  109. }
  110. }