feat: production-grade Live Activity with type-safe phases, decomposed views, previews, and alert transitions

- Replace raw string phase model with WorkoutPhase enum (Codable, Sendable, CaseIterable)
  with built-in .capitalized display name and SwiftUI .color per phase
- Decompose WorkoutLiveActivity into reusable view structs: PhasePill, CountdownText,
  WorkoutProgressBar, MusicInfoRow, HeartRateBadge, PhaseIndicatorDot, WorkoutLockScreenView,
  WorkoutSmallView — following CraftingSwift iOS 26 architecture patterns
- Add AlertConfiguration on work/rest/complete phase transitions so Dynamic Island
  expands and lights up at key moments
- Add 13 #Preview blocks across both widgets covering all presentation types:
  lock screen, expanded, compact, minimal — for instant Xcode Canvas feedback
- Add stale state handling (context.isStale shows 'Last updated' indicator)
- MusicLiveActivity: 5 new #Preview blocks for playing/paused/expanded/compact/minimal
This commit is contained in:
Millian Lamiaux
2026-05-16 15:28:45 +02:00
parent 95f34e6471
commit dc3ff15e81
5 changed files with 476 additions and 255 deletions

View File

@@ -1,10 +1,44 @@
import ActivityKit
import Foundation
#if canImport(SwiftUI)
import SwiftUI
#endif
enum WorkoutPhase: String, Codable, Hashable, Sendable, CaseIterable {
case prep
case warmup
case work
case rest
case interBlockRest
case cooldown
case complete
var capitalized: String {
switch self {
case .interBlockRest: return "Inter-Block Rest"
default: return rawValue.capitalized
}
}
#if canImport(SwiftUI)
var color: Color {
switch self {
case .prep: return Color(red: 1.0, green: 0.58, blue: 0.0)
case .warmup: return Color(red: 1.0, green: 0.58, blue: 0.0)
case .work: return Color(red: 1.0, green: 0.42, blue: 0.21)
case .rest, .interBlockRest: return Color(red: 0.35, green: 0.78, blue: 0.98)
case .cooldown: return Color(red: 0.35, green: 0.78, blue: 0.98)
case .complete: return Color(red: 0.19, green: 0.82, blue: 0.35)
}
}
#endif
}
struct WorkoutActivityAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable, Sendable {
var exerciseName: String
var phase: String
var phase: WorkoutPhase
var phaseEndDate: Date
var roundCurrent: Int
var roundTotal: Int