diff --git a/DE/DE/Sources/Core/CommonUI/Cells/ReviewCollectionViewCell.swift b/DE/DE/Sources/Core/CommonUI/Cells/ReviewCollectionViewCell.swift index 97512237..63e6118a 100644 --- a/DE/DE/Sources/Core/CommonUI/Cells/ReviewCollectionViewCell.swift +++ b/DE/DE/Sources/Core/CommonUI/Cells/ReviewCollectionViewCell.swift @@ -7,8 +7,8 @@ import Then import DesignSystem public class ReviewCollectionViewCell: UICollectionViewCell { - public static let identifier = "ReviewCollectionViewCell" + var isExpanded = false private var toggleBottomConstraint: Constraint? private var reviewBottomConstraint: Constraint? @@ -17,6 +17,7 @@ public class ReviewCollectionViewCell: UICollectionViewCell { public lazy var nickname = UILabel().then { $0.textColor = AppColor.gray100 $0.font = UIFont.pretendard(.medium, size: 16) + $0.setContentHuggingPriority(.required, for: .vertical) } public lazy var score = UILabel() @@ -60,6 +61,7 @@ public class ReviewCollectionViewCell: UICollectionViewCell { private func addComponents() { contentView.addSubviews(nickname, score, review, date, toggleButton) + } private func constraints() { @@ -85,7 +87,7 @@ public class ReviewCollectionViewCell: UICollectionViewCell { } toggleButton.snp.makeConstraints { - $0.top.equalTo(review.snp.bottom).offset(2) + $0.top.greaterThanOrEqualTo(review.snp.bottom).offset(2) $0.leading.equalTo(review.snp.leading) $0.bottom.equalToSuperview().offset(-10) self.toggleBottomConstraint = $0.bottom.equalToSuperview().offset(-12).constraint @@ -96,6 +98,8 @@ public class ReviewCollectionViewCell: UICollectionViewCell { AppTextStyle.KR.body1.apply(to: nickname, text: model.name, color: AppColor.gray100) AppTextStyle.KR.body2 .apply(to: score, text: "★ \(String(model.rating))", color: AppColor.purple100) + + AppTextStyle.KR.body3.apply(to: review, text: model.contents, color: AppColor.gray90) if let data = model.createdAt.toFlexibleDotFormattedDate() { @@ -106,25 +110,30 @@ public class ReviewCollectionViewCell: UICollectionViewCell { review.numberOfLines = isExpanded ? 0 : 2 toggleButton.setTitle(isExpanded ? "접기" : "더보기", for: .normal) let shouldShowToggle = isReviewTextTruncated() - toggleButton.isHidden = !shouldShowToggle + toggleButton.isHidden = !(shouldShowToggle > 2) // 리뷰내 2줄 초과인지 아닌지에 따른 제약 활성화/비활성화 - if shouldShowToggle { + if shouldShowToggle > 2 { toggleBottomConstraint?.activate() reviewBottomConstraint?.deactivate() } else { toggleBottomConstraint?.deactivate() reviewBottomConstraint?.activate() } + + if shouldShowToggle == 1 { + let reviewString = "\(model.contents)\n" + AppTextStyle.KR.body3.apply(to: review, text: reviewString, color: AppColor.gray90) + } } - private func isReviewTextTruncated() -> Bool { - guard let text = review.text else { return false } + private func isReviewTextTruncated() -> Int { + guard let text = review.text else { return 0 } let labelWidth = contentView.frame.width - 30 let labelFont = review.font ?? UIFont.systemFont(ofSize: 16) let lineSpacing = review.font.pointSize * 0.3 let numberOfLines = text.numberOfLines(width: labelWidth, font: labelFont, lineSpacing: lineSpacing) - return numberOfLines > 2 + return numberOfLines } } diff --git a/DE/DE/Sources/Core/CommonUI/View/ReviewView.swift b/DE/DE/Sources/Core/CommonUI/View/ReviewView.swift index d7d33829..5238dfdc 100644 --- a/DE/DE/Sources/Core/CommonUI/View/ReviewView.swift +++ b/DE/DE/Sources/Core/CommonUI/View/ReviewView.swift @@ -131,7 +131,13 @@ public class ReviewView: UIView { noReviewLabel.sizeToFit() } + @MainActor public func configure(_ model: WineAverageReviewModel) { score = model.avgMemberRating } + + @MainActor + public func configureButton(_ isHidden: Bool) { + moreBtn.isHidden = isHidden + } } diff --git a/DE/DE/Sources/Features/Search/ViewControllers/EntireReviewViewController.swift b/DE/DE/Sources/Features/Search/ViewControllers/EntireReviewViewController.swift index 956aabdb..6aaf5281 100644 --- a/DE/DE/Sources/Features/Search/ViewControllers/EntireReviewViewController.swift +++ b/DE/DE/Sources/Features/Search/ViewControllers/EntireReviewViewController.swift @@ -41,15 +41,15 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable { view.addSubview(indicator) view.showColorBlockingView() setupDropdownAction() - } - - public override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - logScreenView(fileName: #file) Task { do { - try await callEntireReviewAPI(wineId: self.wineId, sortType: "최신순", page: 0) + try await callEntireReviewAPI( + wineId: self.wineId, + sortType: "최신순", + page: 0, + vintage: vintage + ) self.view.hideBlockingView() } catch { self.view.hideBlockingView() @@ -58,6 +58,11 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable { } } + public override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + logScreenView(fileName: #file) + } + private func setupNavigationBar() { navigationBarManager.addBackButton( to: navigationItem, @@ -105,8 +110,10 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable { private func setupDropdownAction() { logButtonClick(screenName: screenName, buttonName: Tracking.ButtonEvent.dropdownBtnTapped, fileName: #file) + entireReviewView.dropdownView.onOptionSelected = { [weak self] selectedOption in guard let self = self else { return } + if selectedOption == "최신 순" { currentType = "최신순" } else if selectedOption == "오래된 순" { @@ -117,9 +124,16 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable { currentType = "별점 낮은 순" } self.view.showBlockingView() + Task { do { - try await self.callEntireReviewAPI(wineId: self.wineId, sortType: self.currentType, page: 0) + try await self.callEntireReviewAPI( + wineId: self.wineId, + sortType: self.currentType, + page: 0, + vintage: self.vintage + ) + DispatchQueue.main.async { // 강제로 맨위로 올리기 self.entireReviewView.reviewCollectionView.setContentOffset(.zero, animated: true) @@ -134,7 +148,12 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable { } func callEntireReviewAPI(wineId: Int, sortType: String, page: Int, vintage: Int? = nil) async throws { - guard let response = try await networkService.fetchWineReviews(wineId: wineId, vintageYear: vintage, sortType: sortType, page: page) else { + guard let response = try await networkService.fetchWineReviews( + wineId: wineId, + vintageYear: vintage, + sortType: sortType, + page: page + ) else { return } @@ -242,7 +261,12 @@ extension EntireReviewViewController: UICollectionViewDataSource, UICollectionVi self.view.showBlockingView() Task { do { - try await callEntireReviewAPI(wineId: self.wineId, sortType: currentType, page: currentPage + 1) + try await callEntireReviewAPI( + wineId: self.wineId, + sortType: currentType, + page: currentPage + 1, + vintage: vintage + ) self.view.hideBlockingView() } catch { self.view.hideBlockingView() diff --git a/DE/DE/Sources/Features/Search/ViewControllers/WineDetailViewController.swift b/DE/DE/Sources/Features/Search/ViewControllers/WineDetailViewController.swift index 2a4c880c..9970c07b 100644 --- a/DE/DE/Sources/Features/Search/ViewControllers/WineDetailViewController.swift +++ b/DE/DE/Sources/Features/Search/ViewControllers/WineDetailViewController.swift @@ -307,9 +307,9 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase } private func updateReviewView() { + reviewView.configureButton(reviewData.count != 3) + if reviewData.isEmpty { - // 리뷰가 없을 때 - reviewView.moreBtn.isHidden = true reviewView.reviewCollectionView.isHidden = true reviewView.reviewCollectionView.snp.updateConstraints { $0.height.equalTo(0) @@ -318,7 +318,6 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase reviewView.noReviewLabel.isHidden = false } else { // 리뷰가 있을 때 - reviewView.moreBtn.isHidden = false reviewView.reviewCollectionView.isHidden = false reviewView.scoreLabel.isHidden = false reviewView.noReviewLabel.isHidden = true @@ -348,11 +347,6 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase let tastingNoteString = noseNotes.joined(separator: ", ") - DispatchQueue.main.async { [weak self] in - //self.setupNavigationBar() // 제목 및 좋아요 설정 - self?.updateReviewView() - } - let infoData = WineDetailInfoModel( wineName:wineResponse.name, rating:wineResponse.vivinoRating, @@ -402,6 +396,7 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase self.wineDetailsView.configure(infoData) self.averageTastingNoteView.configure(avgData, self.vintage) + self.updateReviewView() self.reviewView.configure(reviewData) self.reviewView.reviewCollectionView.reloadData() }