mycode/myApp/Keging/IOS/ContentView.swift
songyc macbook eba01b570f fix(keging): 실기기 2차 피드백 — 중단 UI 인라인화·통계 위로 스와이프·진동 3종 Core Haptics 재설계
① 중단 확인: 하단 시트(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
2026-08-30 09:39:37 +09:00

230 lines
8.4 KiB
Swift

//
// ContentView.swift
// Keging
//
// + · . .
//
import SwiftUI
struct ContentView: View {
@EnvironmentObject private var engine: KegelEngine
@EnvironmentObject private var settings: SettingsStore
@Environment(\.scenePhase) private var scenePhase
@State private var showTimerSettings = false
@State private var showAppSettings = false
@State private var showHelp = false
@State private var showStats = false
var body: some View {
ZStack {
AppTheme.background.ignoresSafeArea()
mainScreen
if showStats {
StatsView(onClose: closeStats)
.transition(.move(edge: .bottom))
.zIndex(2)
}
}
.sheet(isPresented: $showTimerSettings) { TimerSettingsView() }
.sheet(isPresented: $showAppSettings) { AppSettingsView() }
.sheet(isPresented: $showHelp) { HelpView() }
.fullScreenCover(isPresented: workoutPresented) { WorkoutView() }
.onReceive(NotificationCenter.default.publisher(for: .startWorkoutRequested)) { _ in
startFromShortcut()
}
.onChange(of: scenePhase) {
//
if scenePhase == .active { KegelEngine.shared.resyncAfterWake() }
}
.onAppear {
if AppLaunchState.shared.startRequested { startFromShortcut() }
#if DEBUG
if CommandLine.arguments.contains("-openStats") { showStats = true }
if CommandLine.arguments.contains("-openHelp") { showHelp = true }
if CommandLine.arguments.contains("-openSettings") { showAppSettings = true }
if CommandLine.arguments.contains("-openTimerSettings") { showTimerSettings = true }
if CommandLine.arguments.contains("-autoStart") { WorkoutCoordinator.shared.startWorkout() }
#endif
}
}
// MARK:
private var mainScreen: some View {
VStack(spacing: 0) {
HStack(alignment: .top) {
cornerButton(symbol: "gearshape.fill", label: Text("설정")) { showAppSettings = true }
Spacer()
cornerButton(symbol: "slider.horizontal.3", label: Text("운동 세팅")) { showTimerSettings = true }
}
.padding(.horizontal, 20)
.padding(.top, 8)
Spacer()
Button {
WorkoutCoordinator.shared.startWorkout()
} label: {
startButtonLabel
}
.buttonStyle(.plain)
.accessibilityLabel(Text("케겔 운동 시작"))
Button {
showTimerSettings = true
} label: {
HStack(spacing: 12) {
summaryChip(
symbol: KegelPhase.contract.symbolName,
value: String(localized: "\(settings.config.contractSeconds)"),
label: Text("수축"),
color: AppTheme.green
)
summaryChip(
symbol: KegelPhase.relax.symbolName,
value: String(localized: "\(settings.config.relaxSeconds)"),
label: Text("이완"),
color: AppTheme.yellow
)
summaryChip(
symbol: "repeat",
value: String(localized: "\(settings.config.reps)"),
label: Text("횟수"),
color: AppTheme.green
)
}
}
.buttonStyle(.plain)
.padding(.top, 34)
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text("운동 세팅 열기 — 현재 \(settings.config.summaryText)"))
Spacer()
Spacer()
// : = ( ), =
ZStack {
Button {
openStats()
} label: {
VStack(spacing: 2) {
Image(systemName: "chevron.compact.up")
.font(.body)
.foregroundStyle(.secondary)
Capsule().fill(.secondary.opacity(0.5)).frame(width: 36, height: 5)
}
.padding(.bottom, 6)
}
.buttonStyle(.plain)
.accessibilityLabel(Text("통계 보기"))
HStack {
Spacer()
cornerButton(symbol: "questionmark", label: Text("도움말")) { showHelp = true }
}
}
.padding(.horizontal, 20)
.padding(.bottom, 8)
}
.contentShape(Rectangle())
.gesture(
DragGesture(minimumDistance: 25)
.onEnded { value in
if value.translation.height < -60, abs(value.translation.width) < 100 {
openStats()
}
}
)
}
private var startButtonLabel: some View {
ZStack {
Circle()
.fill(
RadialGradient(
colors: [AppTheme.green.opacity(0.22), .clear],
center: .center, startRadius: 100, endRadius: 165
)
)
.frame(width: 330, height: 330)
Circle()
.fill(
LinearGradient(
colors: [AppTheme.green, AppTheme.green.opacity(0.82)],
startPoint: .top, endPoint: .bottom
)
)
.frame(width: 236, height: 236)
.shadow(color: AppTheme.green.opacity(0.35), radius: 24, x: 0, y: 10)
VStack(spacing: 8) {
Image(systemName: "play.fill").font(.system(size: 40, weight: .bold))
Text("시작").font(.title.bold())
}
.foregroundStyle(startButtonForeground)
}
.frame(width: 330, height: 330)
}
///
private var startButtonForeground: Color {
Color(light: .white, dark: Color(hex: "#0F2018"))
}
private func summaryChip(symbol: String, value: String, label: Text, color: Color) -> some View {
VStack(spacing: 6) {
Image(systemName: symbol)
.font(.subheadline.weight(.semibold))
.foregroundStyle(color)
Text(value)
.font(.title3.bold())
.monospacedDigit()
.foregroundStyle(.primary)
label
.font(.caption)
.foregroundStyle(.secondary)
}
.frame(width: 92)
.padding(.vertical, 14)
.background(AppTheme.surface, in: RoundedRectangle(cornerRadius: 18))
.shadow(color: .black.opacity(0.06), radius: 10, x: 0, y: 3)
}
private func cornerButton(symbol: String, label: Text, action: @escaping () -> Void) -> some View {
Button(action: action) {
Image(systemName: symbol)
.font(.title3)
.foregroundStyle(.secondary)
.frame(width: 44, height: 44)
.background(AppTheme.surface, in: Circle())
}
.buttonStyle(.plain)
.accessibilityLabel(label)
}
// MARK: ·
private func openStats() {
// ( )
withAnimation(.spring(response: 0.45, dampingFraction: 0.62)) { showStats = true }
}
private func closeStats() {
withAnimation(.spring(response: 0.35, dampingFraction: 0.85)) { showStats = false }
}
private var workoutPresented: Binding<Bool> {
Binding(
get: { engine.state != .idle },
set: { presented in if !presented { engine.acknowledgeFinish() } }
)
}
private func startFromShortcut() {
AppLaunchState.shared.startRequested = false
showStats = false
WorkoutCoordinator.shared.startWorkout()
}
}