From 9479f5b4605b6a1bef917f9a554ff76671abd802 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 30 May 2024 00:57:45 +0900 Subject: [PATCH] =?UTF-8?q?[Fix/#39]=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Challenge/Views/ChallengeView.swift | 134 ++++++++++-------- 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift b/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift index eac3900e..85217a92 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift @@ -60,7 +60,6 @@ extension ChallengeView { .onAppear { viewModel.getChallengeInfo() } - } var emptyChallengeHeaderView: some View { @@ -166,75 +165,92 @@ extension ChallengeView { VStack(alignment: .leading) { if viewModel.days > 0 { ForEach(1...min(isExpanded ? (viewModel.days + 6) / 7 : 2, (viewModel.days + 6) / 7), id: \.self) { week in - HStack { - ForEach(1...7, id: \.self) { day in - let index = (week - 1) * 7 + day - 1 - if index < viewModel.statuses.count { - VStack { - Text("\(index + 1)") - .font(.text6_medium_14) - .foregroundStyle(.gray2) - ZStack { - Circle() - .stroke(index == viewModel.todayIndex ? .bluePurpleOpacity70 : .gray6, lineWidth: 2) - .frame(width: 44, height: 44) - switch viewModel.statuses[index] { - case "UNEARNED": - Image(.failStar) - .resizable() - .frame(width: 24, height: 24) - case "EARNED": - let gradient = LinearGradient( - gradient: Gradient(stops: [ - .init(color: Color(red: 61/255, green: 23/255, blue: 211/255, opacity: 0), location: 0), - .init(color: Color(red: 61/255, green: 23/255, blue: 211/255, opacity: 0.4), location: 1) - ]), - startPoint: .top, - endPoint: .bottom - ) - gradient - .mask(Circle().frame(width: 44, height: 44)) - .frame(width: 44, height: 44) - Image(.successStar) - .resizable() - .frame(width: 24, height: 24) - default: - EmptyView() - } - } - } - } - } - } - .padding(.bottom, 8) + challengeWeekRow(week: week) } } if viewModel.challengeType == .large { + expandButton() + } + } + } + + @ViewBuilder + private func challengeWeekRow(week: Int) -> some View { + HStack { + ForEach(1...7, id: \.self) { day in + challengeDayCell(week: week, day: day) + } + } + .padding(.bottom, 8) + } + + @ViewBuilder + private func expandButton() -> some View { + HStack { + Button(action: { + withAnimation { + isExpanded.toggle() + } + }, label: { HStack { - Button(action: { - withAnimation { - isExpanded.toggle() - } - }, label: { - HStack { - Text(isExpanded ? "접기" : "펼치기") - .font(.detail4_medium_12) - .foregroundStyle(.gray2) - Image(isExpanded ? .chevronUp : .chevronDown) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 8, height: 9) - } - .frame(width: 57, height: 31) - }) + Text(isExpanded ? "접기" : "펼치기") + .font(.detail4_medium_12) + .foregroundStyle(.gray2) + Image(isExpanded ? .chevronUp : .chevronDown) + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 8, height: 9) + } + .frame(width: 57, height: 31) + }) + } + .frame(maxWidth: .infinity) + } + + @ViewBuilder + private func challengeDayCell(week: Int, day: Int) -> some View { + let index = (week - 1) * 7 + day - 1 + if index < viewModel.statuses.count { + VStack { + Text("\(index + 1)") + .font(.text6_medium_14) + .foregroundStyle(.gray2) + ZStack { + Circle() + .stroke(index == viewModel.todayIndex ? .bluePurpleOpacity70 : .gray6, lineWidth: 2) + .frame(width: 44, height: 44) + switch viewModel.statuses[index] { + case "UNEARNED": + Image(.failStar) + .resizable() + .frame(width: 24, height: 24) + case "EARNED": + let gradient = LinearGradient( + gradient: Gradient(stops: [ + .init(color: Color(red: 61/255, green: 23/255, blue: 211/255, opacity: 0), location: 0), + .init(color: Color(red: 61/255, green: 23/255, blue: 211/255, opacity: 0.4), location: 1) + ]), + startPoint: .top, + endPoint: .bottom + ) + gradient + .mask(Circle().frame(width: 44, height: 44)) + .frame(width: 44, height: 44) + Image(.successStar) + .resizable() + .frame(width: 24, height: 24) + default: + EmptyView() + } } - .frame(maxWidth: .infinity) } } } } + + #Preview { ChallengeView(viewModel: .init()) }