Skip to content

Commit

Permalink
[hunnit-log#22] 점수 입력 Row 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongchoyi committed Dec 5, 2020
1 parent d4dc6d0 commit 11dd97e
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HunnitLog/HunnitLog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
562F69AE256ECBD400C50C97 /* AchievedGoalRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562F69AD256ECBD400C50C97 /* AchievedGoalRow.swift */; };
562F69B3256ECC3A00C50C97 /* GoalRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562F69B2256ECC3A00C50C97 /* GoalRow.swift */; };
562F69BB256ECCC400C50C97 /* GoalList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562F69BA256ECCC400C50C97 /* GoalList.swift */; };
56790B61257B792A00920402 /* ScoreRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56790B60257B792A00920402 /* ScoreRow.swift */; };
630EBD102566954500CDFA50 /* HalfableGrayLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630EBD0F2566954500CDFA50 /* HalfableGrayLine.swift */; };
630EBD222566A38800CDFA50 /* RetrospectRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630EBD212566A38700CDFA50 /* RetrospectRow.swift */; };
630EBD2F2566A5F300CDFA50 /* MonthFlagRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 630EBD2E2566A5F300CDFA50 /* MonthFlagRow.swift */; };
Expand Down Expand Up @@ -67,6 +68,7 @@
562F69AD256ECBD400C50C97 /* AchievedGoalRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AchievedGoalRow.swift; sourceTree = "<group>"; };
562F69B2256ECC3A00C50C97 /* GoalRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoalRow.swift; sourceTree = "<group>"; };
562F69BA256ECCC400C50C97 /* GoalList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoalList.swift; sourceTree = "<group>"; };
56790B60257B792A00920402 /* ScoreRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScoreRow.swift; sourceTree = "<group>"; };
630EBD0F2566954500CDFA50 /* HalfableGrayLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HalfableGrayLine.swift; sourceTree = "<group>"; };
630EBD212566A38700CDFA50 /* RetrospectRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetrospectRow.swift; sourceTree = "<group>"; };
630EBD2E2566A5F300CDFA50 /* MonthFlagRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthFlagRow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -140,6 +142,7 @@
562F69B2256ECC3A00C50C97 /* GoalRow.swift */,
562F69AD256ECBD400C50C97 /* AchievedGoalRow.swift */,
562F69BA256ECCC400C50C97 /* GoalList.swift */,
56790B60257B792A00920402 /* ScoreRow.swift */,
);
path = Home;
sourceTree = "<group>";
Expand Down Expand Up @@ -442,6 +445,7 @@
562F69A9256ECA0E00C50C97 /* DateSelectionVIew.swift in Sources */,
630EBD222566A38800CDFA50 /* RetrospectRow.swift in Sources */,
63A4DF14256C193400257ED2 /* CustomAlert.swift in Sources */,
56790B61257B792A00920402 /* ScoreRow.swift in Sources */,
632A107E2566BCDB0085B126 /* RetrospectView.swift in Sources */,
562F698F256EBFAE00C50C97 /* HomeView.swift in Sources */,
E09B973925711196004C882D /* AchievementSetupView.swift in Sources */,
Expand Down
118 changes: 118 additions & 0 deletions HunnitLog/HunnitLog/View/Home/ScoreRow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// ScoreRow.swift
// HunnitLog
//
// Created by 초이 on 2020/12/05.
//

import SwiftUI

struct ScoreRow: View {
@State private var sliderValue: Double = 0

let step: Double = 1
var roundedValue: Double

let title: String
let achievement: Int

private enum Constants {
static let horizontalPadding: CGFloat = 18
static let verticalPadding: CGFloat = 15
static let trailing: CGFloat = 10
static let circleRadius: CGFloat = 47
static let titleFont: Font = .system(size: 17)
static let achievementFont: Font = .system(size: 13)
static let borderWidth: CGFloat = 0.3
static let borderRadius: CGFloat = 13

static let sliderMinValue: CGFloat = -5
static let sliderMaxValue: CGFloat = 5

static let badImageName: String = "imgTextboxBad"
static let notBadImageName: String = "imgTextboxNotbad"
static let sosoImageName: String = "imgTextboxSoso"
static let greatImageName: String = "imgTextboxGreat"
static let excellentImageName: String = "imgTextboxExcellent"
}


var body: some View {
let roundedValue = round(sliderValue/step)*step

HStack(spacing: 7){
VStack{
HStack{
Circle()
.fill(CustomColor.yellow)
.frame(width: Constants.circleRadius, height: Constants.circleRadius)
.padding(.trailing, Constants.trailing)

VStack{
HStack{
Text(title)
.font(Constants.titleFont)
Spacer()
}
HStack{
Text("달성률 \(achievement)%")
.font(Constants.achievementFont)
.foregroundColor(CustomColor.coolGray)
Spacer()
}
}
}

GeometryReader { geometry in
VStack {
HStack{

switch roundedValue {
case -5 ... -4:
Image(Constants.badImageName)
.frame(width: CGFloat(geometry.size.width / 10 * CGFloat(5.9 + sliderValue)), height: 32, alignment: .bottomTrailing)
case -3 ... -2:
Image(Constants.notBadImageName)
.frame(width: CGFloat(geometry.size.width / 10 * CGFloat(5.9 + sliderValue)), height: 32, alignment: .bottomTrailing)
case -1 ... 1:
Image(Constants.sosoImageName)
.frame(width: CGFloat(geometry.size.width / 10 * CGFloat(5.9 + sliderValue)), height: 32, alignment: .bottomTrailing)
case 2 ... 3:
Image(Constants.greatImageName)
.frame(width: CGFloat(geometry.size.width / 10 * CGFloat(5.9 + sliderValue)), height: 32, alignment: .bottomTrailing)
default:
Image(Constants.excellentImageName)
.frame(width: CGFloat(geometry.size.width / 10 * CGFloat(5.9 + sliderValue)), height: 32, alignment: .bottomTrailing)
}
Spacer()
}
Slider(value: $sliderValue, in: -5...5)
.accentColor(CustomColor.lightGray)
}
}
.frame(height: 70)
HStack {
Text("-5")
Spacer()
Text("-3")
Spacer()
Text("0")
Spacer()
Text("+3")
Spacer()
Text("+5")
}
}
}
.padding(.horizontal, Constants.horizontalPadding)
.padding(.vertical, Constants.verticalPadding)
.background(Color.white)
.makeRoundedWithBorder(CustomColor.gray, width:Constants.borderWidth, cornerRadius: Constants.borderRadius)
}
}

struct ScoreRow_Previews: PreviewProvider {
static var previews: some View {
ScoreRow(roundedValue: 0, title: "목표제목입니다목표제목입니다목표제목입니다목표제목입니다목표제목입니다", achievement: 20)
}
}

0 comments on commit 11dd97e

Please sign in to comment.