Skip to content

Commit 2003292

Browse files
committed
Merge branch 'feat/#131-search-feature-module' of https://github.com/PopPool/iOS into feat/#131-search-feature-module
2 parents bb997f6 + 1e6c28f commit 2003292

File tree

4 files changed

+207
-173
lines changed

4 files changed

+207
-173
lines changed

Poppool/PresentationLayer/Presentation/Presentation/Scene/Map/FillterSheetView/BalloonBackgroundView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class BalloonBackgroundView: UIView {
3434
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
3535
collectionView.backgroundColor = .clear
3636
collectionView.isScrollEnabled = false
37-
collectionView.register(BalloonChipCell.self, forCellWithReuseIdentifier: BalloonChipCell.identifier)
37+
collectionView.register(BalloonChipCell.self, forCellWithReuseIdentifier: BalloonChipCell.identifiers)
3838
return collectionView
3939
}()
4040

@@ -289,7 +289,7 @@ extension BalloonBackgroundView: UICollectionViewDataSource {
289289
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
290290
guard
291291
let cell = collectionView.dequeueReusableCell(
292-
withReuseIdentifier: BalloonChipCell.identifier,
292+
withReuseIdentifier: BalloonChipCell.identifiers,
293293
for: indexPath
294294
) as? BalloonChipCell,
295295
let input = tagSection?.inputDataList[indexPath.item]
Lines changed: 121 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,132 @@
11
import UIKit
22

33
import DesignSystem
4+
import Infrastructure
45

56
import SnapKit
7+
import Then
68

79
final class BalloonChipCell: UICollectionViewCell {
8-
static let identifier = "BalloonChipCell"
9-
10-
private let button: PPButton = {
11-
let button = PPButton(
12-
style: .secondary,
13-
text: "",
14-
font: .korFont(style: .medium, size: 11),
15-
cornerRadius: 15
16-
)
17-
18-
button.titleLabel?.lineBreakMode = .byTruncatingTail
19-
button.titleLabel?.adjustsFontSizeToFitWidth = false
20-
return button
21-
}()
22-
23-
override init(frame: CGRect) {
24-
super.init(frame: frame)
25-
contentView.addSubview(button)
26-
setupLayout()
27-
}
28-
29-
required init?(coder: NSCoder) {
30-
fatalError("init(coder:) has not been implemented")
31-
}
32-
33-
private func setupLayout() {
34-
button.snp.makeConstraints { make in
35-
make.edges.equalToSuperview()
36-
}
37-
}
38-
39-
func configure(with title: String, isSelected: Bool) {
40-
button.setTitle(title, for: .normal)
41-
if isSelected {
42-
let checkImage = UIImage(named: "icon_check_white")?.withRenderingMode(.alwaysOriginal)
43-
let resizedImage = checkImage?.resize(to: CGSize(width: 16, height: 16))
44-
button.setImage(resizedImage, for: .normal)
45-
button.semanticContentAttribute = .forceRightToLeft
46-
button.imageEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 0)
47-
button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 10, bottom: 6, right: 12)
48-
button.setBackgroundColor(.blu500, for: .normal)
49-
button.setTitleColor(.white, for: .normal)
50-
button.layer.borderWidth = 0
51-
button.titleLabel?.font = .korFont(style: .bold, size: 11)
52-
53-
} else {
54-
button.setImage(nil, for: .normal)
55-
button.semanticContentAttribute = .unspecified
56-
button.imageEdgeInsets = .zero
57-
button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 12, bottom: 6, right: 12)
58-
button.setBackgroundColor(.white, for: .normal)
59-
button.setTitleColor(.g400, for: .normal)
60-
button.layer.borderWidth = 1
61-
button.layer.borderColor = UIColor.g200.cgColor
62-
button.titleLabel?.font = .korFont(style: .medium, size: 11)
63-
64-
}
65-
}
66-
67-
private var currentAction: UIAction?
68-
69-
var buttonAction: (() -> Void)? {
70-
didSet {
71-
if let oldAction = currentAction {
72-
button.removeAction(oldAction, for: .touchUpInside)
73-
}
74-
75-
let action = UIAction { [weak self] _ in
76-
self?.buttonAction?()
77-
}
78-
button.addAction(action, for: .touchUpInside)
79-
currentAction = action
80-
}
81-
}
10+
11+
private enum Constant {
12+
static let verticalInset: CGFloat = 6
13+
static let selectedLeftInset: CGFloat = 10
14+
static let normalLeftInset: CGFloat = 12
15+
static let rightInset: CGFloat = 12
16+
static let checkIconSize: CGSize = .init(width: 16, height: 16)
17+
static let baselineOffset: CGFloat = -1
18+
static let fontSize: CGFloat = 11
19+
}
20+
21+
private let button = PPButton(
22+
style: .secondary,
23+
text: "",
24+
font: .korFont(style: .medium, size: Constant.fontSize),
25+
cornerRadius: 15
26+
).then {
27+
$0.titleLabel?.lineBreakMode = .byTruncatingTail
28+
$0.titleLabel?.adjustsFontSizeToFitWidth = false
29+
}
30+
31+
private var currentAction: UIAction?
32+
33+
override init(frame: CGRect) {
34+
super.init(frame: frame)
35+
contentView.addSubview(button)
36+
setupLayout()
37+
}
38+
39+
required init?(coder: NSCoder) {
40+
fatalError("init(coder:) has not been implemented")
41+
}
42+
43+
private func setupLayout() {
44+
button.snp.makeConstraints { make in
45+
make.edges.equalToSuperview()
46+
}
47+
}
48+
49+
func configure(with title: String, isSelected: Bool) {
50+
let attributedTitle = NSMutableAttributedString(string: title).then {
51+
$0.addAttribute(
52+
.baselineOffset,
53+
value: Constant.baselineOffset,
54+
range: NSRange(location: .zero, length: $0.length)
55+
)
56+
}
57+
58+
if isSelected {
59+
let checkImage = UIImage(named: "icon_check_white")?.withRenderingMode(.alwaysOriginal).resize(to: Constant.checkIconSize)
60+
61+
button.then {
62+
$0.setImage(checkImage, for: .normal)
63+
$0.semanticContentAttribute = .forceRightToLeft
64+
$0.imageEdgeInsets = .init(top: .zero, left: 1, bottom: .zero, right: .zero)
65+
$0.contentEdgeInsets = .init(
66+
top: Constant.verticalInset,
67+
left: Constant.selectedLeftInset,
68+
bottom: Constant.verticalInset,
69+
right: Constant.rightInset
70+
)
71+
$0.setBackgroundColor(.blu500, for: .normal)
72+
$0.setTitleColor(.white, for: .normal)
73+
$0.layer.borderWidth = .zero
74+
}
75+
76+
attributedTitle.addAttribute(
77+
.font,
78+
value: UIFont.korFont(style: .bold, size: Constant.fontSize)!,
79+
range: NSRange(location: .zero, length: attributedTitle.length)
80+
)
81+
} else {
82+
button.then {
83+
$0.setImage(nil, for: .normal)
84+
$0.semanticContentAttribute = .unspecified
85+
$0.imageEdgeInsets = .zero
86+
$0.contentEdgeInsets = .init(
87+
top: Constant.verticalInset,
88+
left: Constant.normalLeftInset,
89+
bottom: Constant.verticalInset,
90+
right: Constant.rightInset
91+
)
92+
$0.setBackgroundColor(.white, for: .normal)
93+
$0.setTitleColor(.g400, for: .normal)
94+
$0.layer.borderWidth = 1
95+
$0.layer.borderColor = UIColor.g200.cgColor
96+
}
97+
98+
attributedTitle.addAttribute(
99+
.font,
100+
value: UIFont.korFont(style: .medium, size: Constant.fontSize)!,
101+
range: NSRange(location: .zero, length: attributedTitle.length)
102+
)
103+
}
104+
105+
self.button.setAttributedTitle(attributedTitle, for: .normal)
106+
}
107+
108+
var buttonAction: (() -> Void)? {
109+
didSet {
110+
if let oldAction = currentAction {
111+
self.button.removeAction(oldAction, for: .touchUpInside)
112+
}
113+
114+
let action = UIAction { [weak self] _ in
115+
guard let self = self else { return }
116+
self.buttonAction?()
117+
}
118+
119+
self.button.addAction(action, for: .touchUpInside)
120+
self.currentAction = action
121+
}
122+
}
82123
}
83124

84125
extension UIImage {
85-
func resize(to size: CGSize) -> UIImage? {
86-
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
87-
defer { UIGraphicsEndImageContext() }
88-
draw(in: CGRect(origin: .zero, size: size))
89-
return UIGraphicsGetImageFromCurrentImageContext()
90-
}
126+
func resize(to size: CGSize) -> UIImage? {
127+
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
128+
defer { UIGraphicsEndImageContext() }
129+
self.draw(in: CGRect(origin: .zero, size: size))
130+
return UIGraphicsGetImageFromCurrentImageContext()
131+
}
91132
}

0 commit comments

Comments
 (0)