Skip to content

Commit

Permalink
Merge pull request #175 from Zatch-Team/Refactor-CleanArchitecture
Browse files Browse the repository at this point in the history
Refactor/#171: Tag ์ปดํฌ๋„ŒํŠธ ์ถ”๊ฐ€ ๋ฐ ์ ์šฉ
  • Loading branch information
dev-muuu authored Feb 11, 2023
2 parents ecbbf6c + da5d82b commit 373a8f2
Show file tree
Hide file tree
Showing 27 changed files with 956 additions and 698 deletions.
64 changes: 44 additions & 20 deletions Zatch.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Zatch/Global/Source/Component/RadioButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension ZatchComponent{
var isSelected = false{
didSet{
radioButton.isSelected = isSelected
self.tag = isSelected ? Const.ViewTag.select : Const.ViewTag.unselect
self.tag = isSelected ? ViewTag.select : ViewTag.normal
}
}

Expand Down
119 changes: 119 additions & 0 deletions Zatch/Global/Source/Component/Tag/Tag.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// Tag.swift
// Zatch
//
// Created by ๋ฐ•์†Œ์œค on 2023/02/11.
//

import Foundation

extension ZatchComponent{

class PurlpleTag: Tag{

init(configuration: ZatchComponent.Tag.TagType){
super.init(color: .purple, configuration: configuration)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

class YellowTag: Tag{

init(configuration: ZatchComponent.Tag.TagType){
super.init(color: .yellow, configuration: configuration)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

class Tag: UILabel{

var isDisabled = false{
didSet{
isDisabled ? setDisabledState() : setNormalState()
}
}
var isSelected = false{
didSet{
isSelected ? setSelectState() : setNormalState()
}
}

private let configuration: TagType
private let colorType: TagColor

init(color: TagColor, configuration: TagType){
self.colorType = color
self.configuration = configuration
super.init(frame: .zero)
initialize()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func drawText(in rect: CGRect) {
let inset = configuration.padding.inset
super.drawText(in: rect.inset(by: inset))
}

override var intrinsicContentSize: CGSize{
let padding = configuration.padding
var contentSize = super.intrinsicContentSize
contentSize.height += padding.top + padding.bottom
contentSize.width += padding.left + padding.right
return contentSize
}

private func initialize(){
style()
layout()
setNormalState()
}

private func style(){
self.layer.cornerRadius = configuration.height / 2
self.clipsToBounds = true
self.setTypoStyleWithSingleLine(typoStyle: configuration.font)
}

private func layout(){
self.snp.makeConstraints{
$0.height.equalTo(configuration.height)
}
}

private func setNormalState(){
self.tag = ViewTag.normal
self.textColor = colorType.textColor
self.backgroundColor = colorType.backgroundColor
}

private func setDisabledState(){
self.tag = ViewTag.deselect
self.textColor = colorType.disabledTextColor
self.backgroundColor = colorType.disabledBackgroundColor
}

private func setSelectState(){
self.tag = ViewTag.select
self.textColor = colorType.selectedTextColor
self.backgroundColor = colorType.selectedBackgroundColor
}

func setTitle(_ title: String){
self.text = title
}

func setCategoryTitle(categoryId: Int){
let category = ServiceType.Zatch.getCategoryFromCategories(at: categoryId)
self.text = category.title
}
}
}
97 changes: 97 additions & 0 deletions Zatch/Global/Source/Component/Tag/TagStlye.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//
// TagStlye.swift
// Zatch
//
// Created by ๋ฐ•์†Œ์œค on 2023/02/11.
//

import Foundation

extension ZatchComponent.Tag{

enum TagColor{
case purple
case yellow
}

enum TagType{
case height20
}
}

extension ZatchComponent.Tag.TagColor{

struct TagColorStyle{
let textColor: UIColor
let backgroundColor: UIColor
let selectedTextColor: UIColor = .white
let selectedBackgroundColor: UIColor
let disabledTextColor: UIColor
let disabledBackgroundColor: UIColor
}

private var colorInfo: TagColorStyle{
switch self{
case .purple:
return TagColorStyle(textColor: .zatchPurple,
backgroundColor: .purple40,
selectedBackgroundColor: .zatchPurple,
disabledTextColor: .black20,
disabledBackgroundColor: .black10)
case .yellow:
return TagColorStyle(textColor: .zatchDeepYellow,
backgroundColor: .yellow40,
selectedBackgroundColor: .zatchDeepYellow,
disabledTextColor: .black20,
disabledBackgroundColor: .black10)
}
}

var textColor: UIColor{
colorInfo.textColor
}

var backgroundColor: UIColor{
colorInfo.backgroundColor
}

var selectedTextColor: UIColor{
colorInfo.selectedTextColor
}

var selectedBackgroundColor: UIColor{
colorInfo.selectedBackgroundColor
}

var disabledTextColor: UIColor{
colorInfo.disabledTextColor
}

var disabledBackgroundColor: UIColor{
colorInfo.disabledBackgroundColor
}
}

extension ZatchComponent.Tag.TagType{

var padding: ZatchComponent.Padding{
switch self{
case .height20: return ZatchComponent.Padding(left: 8, right: 8, top: 0, bottom: 0)
default: return ZatchComponent.Padding(left: 0, right: 0, top: 0, bottom: 0)
}
}

var font: TypoStyle{
switch self{
case .height20: return .medium12
default: return .medium12
}
}

var height: CGFloat{
switch self{
case .height20: return 20
default: return 20
}
}
}
23 changes: 23 additions & 0 deletions Zatch/Global/Source/Component/Util/Padding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Padding.swift
// Zatch
//
// Created by ๋ฐ•์†Œ์œค on 2023/02/11.
//

import Foundation

extension ZatchComponent{
struct Padding{
let left: CGFloat
let right: CGFloat
let top: CGFloat
let bottom: CGFloat
}
}

extension ZatchComponent.Padding{
var inset: UIEdgeInsets{
UIEdgeInsets(top: self.top, left: self.left, bottom: self.bottom, right: self.right)
}
}
2 changes: 1 addition & 1 deletion Zatch/Global/Source/Component/ZatchComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

class ZatchComponent{

}
11 changes: 6 additions & 5 deletions Zatch/Global/Source/Const.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ struct Const{
static let TOP_OFFSET = 107 //navigationView ๊ณ ๋ คํ•œ top offset
static let headerTop = 47
}

struct ViewTag{
static let select = 1
static let unselect = 0
}
}

struct ViewTag{
static let normal = 1
static let select = 2
static let deselect = 3
}
Loading

0 comments on commit 373a8f2

Please sign in to comment.