-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from Zatch-Team/Refactor-CleanArchitecture
Refactor/#171: Tag ์ปดํฌ๋ํธ ์ถ๊ฐ ๋ฐ ์ ์ฉ
- Loading branch information
Showing
27 changed files
with
956 additions
and
698 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
import Foundation | ||
|
||
class ZatchComponent{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.