Skip to content

Commit

Permalink
[Fix/#39] 코드리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-seonwoo committed May 29, 2024
1 parent 977dadc commit 9479f5b
Showing 1 changed file with 75 additions and 59 deletions.
134 changes: 75 additions & 59 deletions HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ extension ChallengeView {
.onAppear {
viewModel.getChallengeInfo()
}

}

var emptyChallengeHeaderView: some View {
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit 9479f5b

Please # to comment.