Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] BreathingView 모달 변경 #134

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions Spha/Spha/Views/Breathing/BreathingMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,49 @@ import SwiftUI
struct BreathingMainView<BreathViewModel>: 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) {
Expand Down Expand Up @@ -66,7 +80,9 @@ struct BreathingMainView<BreathViewModel>: 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)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Spha/Spha/Views/Breathing/BreathingOutroView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,7 +31,7 @@ struct BreathingOutroView: View {
}
.onAppear {
viewModel.fadeOutAnimation {
router.backToMain()
dismiss()
}
viewModel.recordTestMindfulSession()
}
Expand Down
24 changes: 7 additions & 17 deletions Spha/Spha/Views/Home/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -114,7 +115,8 @@ struct MainView: View {
Spacer()

Button {
viewModel.startBreathingIntro(router: router)
isBreathingViewPresented.toggle()

} label: {
// 임시 버튼 라벨
Image("mainButton")
Expand All @@ -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()
}
Expand Down