watch: fix del sync que nunca llegaba y rediseno estilo Calendar/Weather

- El primer push se descartaba: updateApplicationContext se llamaba antes
  de que WCSession terminara de activarse (activacion asincrona). Ahora
  la sesion se activa al arrancar la app (ContentView), el payload
  pendiente se envia al completarse la activacion, y ademas el reloj
  PIDE los datos al abrirse (sendMessage despierta al iPhone en segundo
  plano y responde con el snapshot del app group)
- Rediseno: Hoy con cabecera del dia en coral y tarjetas degradadas por
  comida (estilo Weather); Semana con circulo de dia a la izquierda y
  hoy relleno en coral (estilo Calendar); complicacion con iconos
  tintados por comida y widgetAccentable
- Verificado con capturas en simulador de Watch sembrando el app group

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013H6bXqGX1ygwib1Dm3n3UG
This commit is contained in:
alexandrev-tibco
2026-09-08 23:32:55 +02:00
parent db36054df0
commit bd8090c845
8 changed files with 216 additions and 55 deletions
+57 -20
View File
@@ -1,54 +1,91 @@
import SwiftUI
/// Today page Weather-app style: a bold colored header with the day, then
/// one vivid gradient card per meal.
struct TodayView: View {
@EnvironmentObject private var store: WatchWeekStore
private var today: WatchWeekPayload.Day? {
store.payload?.days.first(where: \.isToday)
store.payload?.days.first(where: \.isToday) ?? store.payload?.days.first
}
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 8) {
if let today {
Text(today.title)
.font(.headline)
.foregroundStyle(Color(red: 1.0, green: 0.45, blue: 0.35))
HStack(alignment: .firstTextBaseline) {
Text(today.title)
.font(.system(.title3, design: .rounded, weight: .bold))
.foregroundStyle(WatchTheme.coral)
Spacer()
Image(systemName: "fork.knife")
.font(.caption)
.foregroundStyle(.secondary)
}
.padding(.horizontal, 2)
ForEach(Array(today.meals.enumerated()), id: \.offset) { _, meal in
VStack(alignment: .leading, spacing: 2) {
Label(meal.label, systemImage: WatchWeekPayload.icon(for: meal.type))
.font(.caption2)
.foregroundStyle(.secondary)
Text(meal.name ?? "")
.font(.body.weight(.medium))
.lineLimit(2)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(8)
.background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 8))
MealCard(meal: meal)
}
} else {
EmptySyncView()
}
}
}
.navigationTitle("MealMood")
}
}
struct MealCard: View {
let meal: WatchWeekPayload.Meal
private var accent: Color { WatchTheme.accent(for: meal.type) }
var body: some View {
VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 5) {
Image(systemName: WatchWeekPayload.icon(for: meal.type))
.font(.system(size: 11, weight: .bold))
Text(meal.label.uppercased())
.font(.system(size: 11, weight: .bold, design: .rounded))
.tracking(0.5)
}
.foregroundStyle(.white.opacity(0.85))
Text(meal.name ?? "")
.font(.system(.body, design: .rounded, weight: .semibold))
.foregroundStyle(.white)
.lineLimit(2)
.minimumScaleFactor(0.8)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 10)
.padding(.vertical, 9)
.background(
LinearGradient(
colors: [accent, accent.opacity(0.65)],
startPoint: .topLeading,
endPoint: .bottomTrailing
),
in: RoundedRectangle(cornerRadius: 12)
)
}
}
struct EmptySyncView: View {
var body: some View {
VStack(spacing: 8) {
Image(systemName: "iphone.and.arrow.forward")
Image(systemName: "applewatch.radiowaves.left.and.right")
.font(.title3)
.foregroundStyle(.secondary)
// The payload arrives fully localized from the iPhone; the watch
.foregroundStyle(WatchTheme.coral)
// Payload arrives fully localized from the iPhone; the watch
// bundle carries no strings of its own, so this stays neutral.
Text(verbatim: "MealMood")
.font(.system(.caption2, design: .rounded, weight: .semibold))
Image(systemName: "iphone.gen3")
.font(.caption2)
.foregroundStyle(.secondary)
}
.padding(.top, 20)
.frame(maxWidth: .infinity)
.padding(.top, 24)
}
}