|
| 1 | +// |
| 2 | +// ReviewListTableViewCell.swift |
| 3 | +// EATSSU-DEV |
| 4 | +// |
| 5 | +// Created by 최지우 on 2/1/25. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | +import SnapKit |
| 10 | + |
| 11 | +import EATSSUDesign |
| 12 | + |
| 13 | +final class ReviewListTableViewCell: BaseTableViewCell { |
| 14 | + static let id = "ReviewListTableViewCell" |
| 15 | + private var menuChipList = [String]() |
| 16 | + |
| 17 | + // MARK: - Properties |
| 18 | + |
| 19 | + var handler: (() -> Void)? |
| 20 | + var reviewId: Int = .init() |
| 21 | + var menuName: String = .init() |
| 22 | + |
| 23 | + // MARK: - UI Components |
| 24 | + |
| 25 | + lazy var totalRateView = RateNumberView() |
| 26 | + lazy var reactionView = ReactionView() |
| 27 | + |
| 28 | + private var dateLabel: UILabel = { |
| 29 | + let label = UILabel() |
| 30 | + label.text = "2023.03.03" |
| 31 | + label.font = .caption3 |
| 32 | + label.textColor = EATSSUDesignAsset.Color.GrayScale.gray400.color |
| 33 | + return label |
| 34 | + }() |
| 35 | + |
| 36 | + private var userNameLabel: UILabel = { |
| 37 | + let label = UILabel() |
| 38 | + label.text = "hellosoongsil1234" |
| 39 | + label.font = .caption1 |
| 40 | + return label |
| 41 | + }() |
| 42 | + |
| 43 | + private var nickNameLabel: UILabel = { |
| 44 | + let label = UILabel() |
| 45 | + label.text = "깐깐슈" |
| 46 | + label.font = .caption3 |
| 47 | + label.textColor = EATSSUDesignAsset.Color.GrayScale.gray600.color |
| 48 | + return label |
| 49 | + }() |
| 50 | + |
| 51 | + private let userProfileImageView: UIImageView = { |
| 52 | + let imageView = UIImageView(image: EATSSUDesignAsset.Images.profile.image) |
| 53 | + return imageView |
| 54 | + }() |
| 55 | + |
| 56 | + private var sideButton: BaseButton = { |
| 57 | + let button = BaseButton() |
| 58 | +// button.setImage(EATSSUDesignAsset.Images.icInfo.image, for: .normal) |
| 59 | + button.setTitleColor(EATSSUDesignAsset.Color.GrayScale.gray400.color, for: .normal) |
| 60 | + button.titleLabel?.font = .caption2 |
| 61 | + button.setTitle("신고", for: .normal) |
| 62 | + button.configuration?.contentInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 15) |
| 63 | + return button |
| 64 | + }() |
| 65 | + |
| 66 | + var reviewTextLabel: UILabel = { |
| 67 | + let label = UILabel() |
| 68 | + label.font = EATSSUDesignFontFamily.Pretendard.regular.font(size: 14) |
| 69 | + label.text = "여기 계란국 맛집임... 김치볶음밥에 계란후라이 없어서 아쉽 다음에 또 먹어야지dddddfdfdfdfdfdfddfdfdfddfdfdfdfddfddfdfd여기 계란국 맛집임... 김치볶음밥에 계란후라이 없어서 아쉽 다음에 또 먹어야지dddddfdfdfdfdfdfddfdfdfddfdfdfdfddfddfdfd" |
| 70 | + label.numberOfLines = 0 |
| 71 | + return label |
| 72 | + }() |
| 73 | + |
| 74 | + var foodImageView: UIImageView = { |
| 75 | + let imageView = UIImageView() |
| 76 | + imageView.contentMode = .scaleAspectFit |
| 77 | + imageView.isHidden = true |
| 78 | + return imageView |
| 79 | + }() |
| 80 | + |
| 81 | + /// 이름 + 닉네임 |
| 82 | + lazy var nameMenuStackView: UIStackView = { |
| 83 | + let stackView = UIStackView(arrangedSubviews: [userNameLabel, nickNameLabel]) |
| 84 | + stackView.axis = .horizontal |
| 85 | + stackView.spacing = 8.adjusted |
| 86 | + stackView.alignment = .center |
| 87 | + return stackView |
| 88 | + }() |
| 89 | + |
| 90 | + /// (이름 + 닉네임) + 별점 |
| 91 | + lazy var infoStackView: UIStackView = { |
| 92 | + let stackView = UIStackView(arrangedSubviews: [nameMenuStackView, totalRateView]) |
| 93 | + stackView.axis = .vertical |
| 94 | + stackView.spacing = 4.adjusted |
| 95 | + stackView.alignment = .leading |
| 96 | + return stackView |
| 97 | + }() |
| 98 | + |
| 99 | + /// 프로필 + (이름 + 닉네임 + 별점) |
| 100 | + lazy var profileStackView: UIStackView = { |
| 101 | + let stackView = UIStackView(arrangedSubviews: [userProfileImageView, infoStackView]) |
| 102 | + stackView.axis = .horizontal |
| 103 | + stackView.spacing = 8.adjusted |
| 104 | + stackView.alignment = .leading |
| 105 | + stackView.backgroundColor = .purple |
| 106 | + return stackView |
| 107 | + }() |
| 108 | + |
| 109 | + /// 작성일 + 사이드버튼 |
| 110 | + lazy var dateReportStackView: UIStackView = { |
| 111 | + let stackView = UIStackView(arrangedSubviews: [sideButton, dateLabel]) |
| 112 | + stackView.axis = .vertical |
| 113 | + stackView.spacing = 8.adjusted |
| 114 | + stackView.alignment = .trailing |
| 115 | + stackView.backgroundColor = .brown |
| 116 | + return stackView |
| 117 | + }() |
| 118 | + |
| 119 | + /// profileStackView + dateReportStackView |
| 120 | + lazy var topStackView: UIStackView = { |
| 121 | + let stackView = UIStackView(arrangedSubviews: [profileStackView, dateReportStackView]) |
| 122 | + stackView.axis = .horizontal |
| 123 | +// stackView.spacing = 8.adjusted |
| 124 | + stackView.alignment = .fill |
| 125 | + stackView.distribution = .fill |
| 126 | + stackView.backgroundColor = .yellow |
| 127 | + return stackView |
| 128 | + }() |
| 129 | + |
| 130 | + /// 리뷰 텍스트 + 리뷰 이미지 |
| 131 | + lazy var contentStackView: UIStackView = { |
| 132 | + let stackView = UIStackView(arrangedSubviews: [reviewTextLabel, foodImageView]) |
| 133 | + stackView.axis = .vertical |
| 134 | + stackView.spacing = 8.adjusted |
| 135 | + stackView.alignment = .leading |
| 136 | + stackView.backgroundColor = .primary |
| 137 | + return stackView |
| 138 | + }() |
| 139 | + |
| 140 | + /// 추천 메뉴칩 |
| 141 | + private lazy var menuChipCollectionView: UICollectionView = { |
| 142 | + let layout = UICollectionViewFlowLayout() |
| 143 | + layout.scrollDirection = .horizontal |
| 144 | + layout.minimumLineSpacing = 50 |
| 145 | +// layout.minimumInteritemSpacing = 60 |
| 146 | + let cv = UICollectionView(frame: .zero, collectionViewLayout: layout) |
| 147 | + cv.dataSource = self |
| 148 | + cv.backgroundColor = .red |
| 149 | + cv.showsHorizontalScrollIndicator = false |
| 150 | + return cv |
| 151 | + }() |
| 152 | + |
| 153 | + /// 전체 cell |
| 154 | + lazy var cellStackView: UIStackView = { |
| 155 | + let stackView = UIStackView(arrangedSubviews: [ |
| 156 | + topStackView, |
| 157 | + menuChipCollectionView, |
| 158 | + contentStackView, |
| 159 | + reactionView, |
| 160 | + dividerView] |
| 161 | + ) |
| 162 | + stackView.axis = .vertical |
| 163 | + stackView.spacing = 8 |
| 164 | + stackView.alignment = .fill |
| 165 | + stackView.distribution = .fill |
| 166 | + return stackView |
| 167 | + }() |
| 168 | + |
| 169 | + private let dividerView: UIView = { |
| 170 | + let view = UIView() |
| 171 | +// view.backgroundColor = EATSSUDesignAsset.Color.GrayScale.gray200.color |
| 172 | + view.backgroundColor = .red |
| 173 | + return view |
| 174 | + }() |
| 175 | + |
| 176 | + // MARK: - Functions |
| 177 | + |
| 178 | + private func setCollectionView() { |
| 179 | + menuChipCollectionView.register(MenuChipCollectionViewCell.self, |
| 180 | + forCellWithReuseIdentifier: MenuChipCollectionViewCell.id) |
| 181 | + } |
| 182 | + |
| 183 | + override func configureUI() { |
| 184 | + setCollectionView() |
| 185 | + contentView.addSubviews(cellStackView) |
| 186 | + } |
| 187 | + |
| 188 | + override func setLayout() { |
| 189 | +// profileStackView.snp.makeConstraints { make in |
| 190 | +// make.top.equalToSuperview().offset(5) |
| 191 | +// make.leading.equalToSuperview().offset(16) |
| 192 | +// make.height.equalTo(30) |
| 193 | +// } |
| 194 | +// |
| 195 | +// dateReportStackView.snp.makeConstraints { make in |
| 196 | +// make.top.equalTo(profileStackView) |
| 197 | +// make.trailing.equalToSuperview().inset(16) |
| 198 | +// } |
| 199 | + cellStackView.snp.makeConstraints { make in |
| 200 | + make.edges.equalToSuperview() |
| 201 | + } |
| 202 | + |
| 203 | + topStackView.snp.makeConstraints { make in |
| 204 | + make.top.equalToSuperview().offset(5) |
| 205 | + } |
| 206 | + |
| 207 | + menuChipCollectionView.snp.makeConstraints { make in |
| 208 | +// make.top.equalTo(dateReportStackView.snp.bottom).offset(8) |
| 209 | + make.horizontalEdges.equalToSuperview() |
| 210 | + make.height.equalTo(22) |
| 211 | + } |
| 212 | + |
| 213 | + contentStackView.snp.makeConstraints { make in |
| 214 | +// make.top.equalTo(menuChipCollectionView.snp.bottom) |
| 215 | + make.horizontalEdges.equalToSuperview() |
| 216 | + } |
| 217 | + |
| 218 | + foodImageView.snp.makeConstraints { make in |
| 219 | + make.height.width.equalTo(358) |
| 220 | + } |
| 221 | + |
| 222 | + sideButton.snp.makeConstraints { make in |
| 223 | + make.height.equalTo(12.adjusted) |
| 224 | + } |
| 225 | + |
| 226 | + reactionView.snp.makeConstraints { make in |
| 227 | + make.horizontalEdges.equalToSuperview() |
| 228 | + make.height.equalTo(20) |
| 229 | + } |
| 230 | + |
| 231 | + dividerView.snp.makeConstraints { make in |
| 232 | + make.height.equalTo(1) |
| 233 | + } |
| 234 | + |
| 235 | + } |
| 236 | + |
| 237 | + override func prepareForReuse() { |
| 238 | + super.prepareForReuse() |
| 239 | + self.prepare(review: nil, menuChipList: []) |
| 240 | + |
| 241 | + sideButton.setTitle("", for: .normal) |
| 242 | + sideButton.setImage(UIImage(), for: .normal) |
| 243 | + foodImageView.image = UIImage() |
| 244 | + foodImageView.isHidden = true |
| 245 | + } |
| 246 | + |
| 247 | + func prepare(review: String?, menuChipList: [String]) { |
| 248 | + self.userNameLabel.text = review |
| 249 | + self.menuChipList = menuChipList |
| 250 | + self.menuChipCollectionView.reloadData() |
| 251 | + } |
| 252 | + |
| 253 | + @objc |
| 254 | + func touchedSideButtonEvent() { |
| 255 | + handler?() |
| 256 | + } |
| 257 | + |
| 258 | +} |
| 259 | + |
| 260 | +extension ReviewListTableViewCell: UICollectionViewDataSource { |
| 261 | + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| 262 | + return menuChipList.count |
| 263 | + } |
| 264 | + |
| 265 | + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| 266 | + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuChipCollectionViewCell.id, for: indexPath) as! MenuChipCollectionViewCell |
| 267 | + let menuName = self.menuChipList[indexPath.item] |
| 268 | + cell.prepare(name: menuName) |
| 269 | + return cell |
| 270 | + } |
| 271 | +} |
0 commit comments