① 중단 확인: 하단 시트(confirmationDialog) → 버튼 자리에서 펼쳐지는 인라인 확인
(안내 문구 + 계속하기(그린)/중단하기(레드), scale+opacity 전환)
② 통계: 아래→위 스와이프로 반전, 하단 중앙 손잡이(위 화살표+캡슐), 통통 튀는 스프링
(dampingFraction 0.62), 통계 상단에 닫기 손잡이 추가, 닫기=아래로 스와이프
③ 진동 3종(기본·톡톡·지이이잉)으로 재설계 — 체이닝 간격도 길다는 피드백:
- iOS 포그라운드: Core Haptics 정밀 재생(Shared/HapticEnginePlayer) — 기본 0.25s,
톡톡 0.14s×2 시작 간격 0.28s(요구 0.5s 미만), 지이이잉 1.2s 연속, 세기 1.0
- iOS 백그라운드 폴백: 시스템 바이브 완료 체이닝(1방/2방/3방 즉시 잇기)
- 워치: watchOS SDK에 CoreHaptics 부재(실측) — 강한 시스템 햅틱 매핑
(기본=.notification, 톡톡=.directionUp, 지이이잉=.retry — 내장이라 간격 뭉개짐 없음)
- 구버전 저장 패턴 자동 이관, 기본값 수축=지이이잉·이완=기본
- 신규 QA 인자 -confirmStop, 도움말 문구·번역(en/ja) 갱신, stale 정리(카탈로그 0/0)
- 검증: Debug·Release·워치 빌드 그린, 화면 QA(메인 하단 손잡이·통계 시트·중단 인라인 레드)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UPmp29DQHY6Ahfss5SRopT
208 lines
7.9 KiB
Swift
208 lines
7.9 KiB
Swift
//
|
|
// WorkoutView.swift
|
|
// Keging
|
|
//
|
|
// 운동 진행 화면 — 국면 원이 수축 때 줄고 이완 때 커진다. 중단 시 이 세트는 기록 없음.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct WorkoutView: View {
|
|
@EnvironmentObject private var engine: KegelEngine
|
|
@State private var confirmStop = false
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
AppTheme.background.ignoresSafeArea()
|
|
switch engine.state {
|
|
case let .running(phase, rep, phaseStart, phaseEnd):
|
|
runningView(phase: phase, rep: rep, phaseStart: phaseStart, phaseEnd: phaseEnd)
|
|
case let .finished(reps):
|
|
finishedView(reps: reps)
|
|
case .idle:
|
|
Color.clear
|
|
}
|
|
}
|
|
.onAppear {
|
|
#if DEBUG
|
|
if CommandLine.arguments.contains("-confirmStop") { confirmStop = true }
|
|
#endif
|
|
}
|
|
}
|
|
|
|
private func runningView(phase: KegelPhase, rep: Int, phaseStart: Date, phaseEnd: Date) -> some View {
|
|
let phaseColor = Self.color(for: phase)
|
|
let progress = phase == .prepare
|
|
? 0
|
|
: (Double(rep - 1) + (phase == .relax ? 0.5 : 0)) / Double(max(1, engine.config.reps))
|
|
return VStack(spacing: 0) {
|
|
HStack(alignment: .firstTextBaseline, spacing: 5) {
|
|
Text(verbatim: "\(rep)")
|
|
.font(.system(size: 46, weight: .bold))
|
|
.monospacedDigit()
|
|
.foregroundStyle(phaseColor)
|
|
.contentTransition(.numericText())
|
|
.animation(.snappy, value: rep)
|
|
Text(verbatim: "/ \(engine.config.reps)")
|
|
.font(.title3.weight(.semibold))
|
|
.monospacedDigit()
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.padding(.top, 16)
|
|
.accessibilityElement(children: .ignore)
|
|
.accessibilityLabel(Text("현재 \(rep)번째, 전체 \(engine.config.reps)회"))
|
|
|
|
Spacer()
|
|
|
|
ZStack {
|
|
// 세트 진행 링 — 국면 색으로 채워진다
|
|
Circle()
|
|
.stroke(AppTheme.surface, lineWidth: 10)
|
|
.frame(width: 344, height: 344)
|
|
Circle()
|
|
.trim(from: 0, to: progress)
|
|
.stroke(phaseColor.opacity(0.85), style: StrokeStyle(lineWidth: 10, lineCap: .round))
|
|
.rotationEffect(.degrees(-90))
|
|
.frame(width: 344, height: 344)
|
|
.animation(.easeInOut(duration: 0.5), value: progress)
|
|
PhaseCircle(phase: phase, phaseStart: phaseStart, phaseEnd: phaseEnd)
|
|
VStack(spacing: 6) {
|
|
Text(phase.label)
|
|
.font(.system(size: 44, weight: .bold))
|
|
Text(timerInterval: phaseStart...phaseEnd, countsDown: true)
|
|
.font(.title2.weight(.medium))
|
|
.monospacedDigit()
|
|
.opacity(0.85)
|
|
}
|
|
.foregroundStyle(Self.textColor(for: phase))
|
|
}
|
|
|
|
Spacer()
|
|
|
|
// 중단 확인 — 버튼 자리에서 바로 펼쳐지는 인라인 방식 (하단 시트가 뚝 떨어져 보이던 문제 해소)
|
|
Group {
|
|
if confirmStop {
|
|
VStack(spacing: 12) {
|
|
Text("중단하면 이 세트는 기록되지 않아요.")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
HStack(spacing: 12) {
|
|
Button {
|
|
withAnimation(.snappy) { confirmStop = false }
|
|
} label: {
|
|
Text("계속하기")
|
|
.font(.headline)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
Button(role: .destructive) {
|
|
engine.stop()
|
|
} label: {
|
|
Text("중단하기")
|
|
.font(.headline)
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.tint(.red)
|
|
}
|
|
}
|
|
.padding(.horizontal, 24)
|
|
.transition(.scale(scale: 0.9).combined(with: .opacity))
|
|
} else {
|
|
Button {
|
|
withAnimation(.snappy) { confirmStop = true }
|
|
} label: {
|
|
Text("중단")
|
|
.font(.headline)
|
|
.frame(maxWidth: 160)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.tint(.red)
|
|
.transition(.scale(scale: 0.9).combined(with: .opacity))
|
|
}
|
|
}
|
|
.padding(.bottom, 30)
|
|
}
|
|
}
|
|
|
|
/// 준비=차분한 회그린, 수축=그린, 이완=앰버
|
|
static func color(for phase: KegelPhase) -> Color {
|
|
switch phase {
|
|
case .prepare: Color(light: Color(hex: "#7C8A81"), dark: Color(hex: "#5E6B64"))
|
|
case .contract: AppTheme.green
|
|
case .relax: AppTheme.yellow
|
|
}
|
|
}
|
|
|
|
static func textColor(for phase: KegelPhase) -> Color {
|
|
switch phase {
|
|
case .prepare: Color(light: .white, dark: Color(hex: "#10140F"))
|
|
case .contract: Color(light: .white, dark: Color(hex: "#0F2018"))
|
|
case .relax: Color(hex: "#33260A")
|
|
}
|
|
}
|
|
|
|
private func finishedView(reps: Int) -> some View {
|
|
VStack(spacing: 18) {
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.font(.system(size: 84))
|
|
.foregroundStyle(AppTheme.green)
|
|
Text("완료!")
|
|
.font(.largeTitle.bold())
|
|
Text("\(reps)회를 모두 마쳤어요.")
|
|
.font(.body)
|
|
.foregroundStyle(.secondary)
|
|
Button {
|
|
engine.acknowledgeFinish()
|
|
} label: {
|
|
Text("확인")
|
|
.font(.headline)
|
|
.frame(maxWidth: 160)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.padding(.top, 12)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 수축이면 오므라들고 이완이면 부풀어 오르는 국면 원 — 색도 국면 따라(수축 그린·이완 앰버)
|
|
private struct PhaseCircle: View {
|
|
let phase: KegelPhase
|
|
let phaseStart: Date
|
|
let phaseEnd: Date
|
|
|
|
@State private var scale: CGFloat = 1
|
|
|
|
private var color: Color { WorkoutView.color(for: phase) }
|
|
|
|
var body: some View {
|
|
Circle()
|
|
.fill(
|
|
LinearGradient(
|
|
colors: [color, color.opacity(0.8)],
|
|
startPoint: .top, endPoint: .bottom
|
|
)
|
|
)
|
|
.frame(width: 300, height: 300)
|
|
.scaleEffect(scale)
|
|
.shadow(color: color.opacity(0.3), radius: 26, x: 0, y: 10)
|
|
.animation(.easeInOut(duration: 0.4), value: phase)
|
|
.onAppear { animate() }
|
|
.onChange(of: phase) { animate() }
|
|
}
|
|
|
|
private func animate() {
|
|
let duration = max(0.3, phaseEnd.timeIntervalSince(phaseStart))
|
|
// 준비: 작게 → 천천히 부풀며 첫 수축(가득 찬 원에서 오므리기)에 이어짐
|
|
let (from, to): (CGFloat, CGFloat) = switch phase {
|
|
case .prepare: (0.62, 1.0)
|
|
case .contract: (1.0, 0.62)
|
|
case .relax: (0.62, 1.0)
|
|
}
|
|
var transaction = Transaction()
|
|
transaction.disablesAnimations = true
|
|
withTransaction(transaction) { scale = from }
|
|
withAnimation(.easeInOut(duration: duration)) { scale = to }
|
|
}
|
|
}
|