diff --git a/Spha/Spha/Views/Breathing/BreathingMainView.swift b/Spha/Spha/Views/Breathing/BreathingMainView.swift index 9e03b7f..9879681 100644 --- a/Spha/Spha/Views/Breathing/BreathingMainView.swift +++ b/Spha/Spha/Views/Breathing/BreathingMainView.swift @@ -10,35 +10,49 @@ import SwiftUI struct BreathingMainView: View where BreathViewModel: BreathingManager { @EnvironmentObject var router: RouterManager @ObservedObject private var viewModel: BreathViewModel - + @State private var showOutro = false + init(breathManager: BreathViewModel) { self.viewModel = breathManager } var body: some View { - VStack { - MultiMP4PlayerView(videoNames: BreathingPhase.boxBreathingSequence) - .allowsHitTesting(false) - .frame(width: 300, height: 300) - .padding(.top, 164) - - if viewModel.showTimer { - Text("\(Int(viewModel.timerCount))") - .font(.title) - .foregroundColor(.white) - .padding(.top, 10) - .transition(.opacity) + ZStack { + VStack { + RoundedRectangle(cornerRadius: 8) + .frame(width: 80, height: 2) + .padding(.top, 16) + + MultiMP4PlayerView(videoNames: BreathingPhase.boxBreathingSequence) + .allowsHitTesting(false) + .frame(width: 300, height: 300) + .padding(.top, 164) + + if viewModel.showTimer { + Text("\(Int(viewModel.timerCount))") + .font(.title) + .foregroundColor(.white) + .padding(.top, 10) + .transition(.opacity) + } + + Spacer() + + if viewModel.showText && viewModel.activeCircle < 2 { + Text(viewModel.phaseText) + .customFont(.body_0) + .foregroundColor(.gray0) + .padding(.bottom, 153) + .transition(.opacity) + } } - Spacer() - - if viewModel.showText && viewModel.activeCircle < 2 { - Text(viewModel.phaseText) - .customFont(.body_0) - .foregroundColor(.gray0) - .padding(.bottom, 153) - .transition(.opacity) + if showOutro { + BreathingOutroView() + .transition(.opacity) // 페이드 효과 + .zIndex(1) // 항상 최상위에 위치 } + } .toolbar { ToolbarItem(placement: .navigationBarLeading) { @@ -66,7 +80,9 @@ struct BreathingMainView: View where BreathViewModel: Breathing } .onChange(of: viewModel.isBreathingCompleted) { oldValue, newValue in if !newValue { return } - router.push(view: .breathingOutroView) + showOutro = true + // dismiss() // BreathingMainView를 내림 + // router.push(view: .breathingOutroView) } } } diff --git a/Spha/Spha/Views/Breathing/BreathingOutroView.swift b/Spha/Spha/Views/Breathing/BreathingOutroView.swift index 8b0e65f..38ce0b0 100644 --- a/Spha/Spha/Views/Breathing/BreathingOutroView.swift +++ b/Spha/Spha/Views/Breathing/BreathingOutroView.swift @@ -9,6 +9,7 @@ import SwiftUI struct BreathingOutroView: View { @EnvironmentObject var router: RouterManager + @Environment(\.dismiss) var dismiss @StateObject private var viewModel = BreathingOutroViewModel() var body: some View { @@ -30,7 +31,7 @@ struct BreathingOutroView: View { } .onAppear { viewModel.fadeOutAnimation { - router.backToMain() + dismiss() } viewModel.recordTestMindfulSession() } diff --git a/Spha/Spha/Views/Home/MainView.swift b/Spha/Spha/Views/Home/MainView.swift index 75746f4..8fff53e 100644 --- a/Spha/Spha/Views/Home/MainView.swift +++ b/Spha/Spha/Views/Home/MainView.swift @@ -6,6 +6,7 @@ struct MainView: View { @State private var introOpacity = 0.0 @State private var isFirstLaunch: Bool = !UserDefaults.standard.bool(forKey: "hasLaunchedBefore") + @State private var isBreathingViewPresented = false var body: some View { ZStack { @@ -114,7 +115,8 @@ struct MainView: View { Spacer() Button { - viewModel.startBreathingIntro(router: router) + isBreathingViewPresented.toggle() + } label: { // 임시 버튼 라벨 Image("mainButton") @@ -133,28 +135,16 @@ struct MainView: View { .transition(.opacity) // 페이드 효과 .zIndex(1) // 항상 최상위에 위치 } - - // BreathingIntroView 오버레이 뷰 - if viewModel.showBreathingIntro { - Color.black - .opacity(viewModel.breathingIntroOpacity) - .edgesIgnoringSafeArea(.all) - .transition(.opacity) // Fade-in - } } + .sheet(isPresented: $isBreathingViewPresented) { + BreathingMainView(breathManager: BreathingMainViewModel()) + } + .onAppear { - // Notification을 관찰하여 상태 초기화 - NotificationCenter.default.addObserver(forName: RouterManager.backToMainNotification, object: nil, queue: .main) { _ in - viewModel.resetBreathingIntro() - } - if !isFirstLaunch { viewModel.updateTodayRecord() } } - .onDisappear { - NotificationCenter.default.removeObserver(self, name: RouterManager.backToMainNotification, object: nil) - } .onChange(of: self.isFirstLaunch) { oldValue, newValue in viewModel.updateTodayRecord() }