Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merge] #93 - 상세페이지 리뷰 탭 더보기 구현 #105

Merged
merged 7 commits into from
Jul 16, 2022
Merged
37 changes: 31 additions & 6 deletions HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
695758E42881852E00E36789 /* CopingEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopingEmptyView.swift; sourceTree = "<group>"; };
695758EB28830E3000E36789 /* SplashVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashVC.swift; sourceTree = "<group>"; };
695758ED28830E3F00E36789 /* Splash.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Splash.storyboard; sourceTree = "<group>"; };
6E596B9EBEC8B18D4DE266B6 /* Pods-HealthFoodMe.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HealthFoodMe.release.xcconfig"; path = "Target Support Files/Pods-HealthFoodMe/Pods-HealthFoodMe.release.xcconfig"; sourceTree = "<group>"; };
A9325273287D3065001EDF50 /* SearchResultTVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultTVC.swift; sourceTree = "<group>"; };
A9325276287D4F10001EDF50 /* SearchResultModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultModel.swift; sourceTree = "<group>"; };
A932527D287DD261001EDF50 /* SearchResultVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchResultVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -423,6 +424,33 @@
path = HamburgerBarScene;
sourceTree = "<group>";
};
3B3DCF472882B534009256BD /* Common */ = {
isa = PBXGroup;
children = (
3BDE7F282882054200EE7F47 /* ReviewEmptyViewCVC.swift */,
3BC01F88287F1DFA006C2181 /* ReviewHeaderCVC.swift */,
);
path = Common;
sourceTree = "<group>";
};
3B3DCF482882B540009256BD /* BlogReview */ = {
isa = PBXGroup;
children = (
3BC01F83287EAE48006C2181 /* BlogReviewCVC.swift */,
);
path = BlogReview;
sourceTree = "<group>";
};
3B3DCF492882B55D009256BD /* Review */ = {
isa = PBXGroup;
children = (
3B723C902880037100822B7C /* ReviewPhotoCVC.swift */,
3BC01F7A287E89D2006C2181 /* ReviewCVC.swift */,
3B723C8A287FF81800822B7C /* TagCVC.swift */,
);
path = Review;
sourceTree = "<group>";
};
3B723CA72881D43B00822B7C /* VC */ = {
isa = PBXGroup;
children = (
Expand All @@ -435,12 +463,9 @@
3BC01F79287E8917006C2181 /* Cells */ = {
isa = PBXGroup;
children = (
3BC01F83287EAE48006C2181 /* BlogReviewCVC.swift */,
3BC01F88287F1DFA006C2181 /* ReviewHeaderCVC.swift */,
3BC01F7A287E89D2006C2181 /* ReviewCVC.swift */,
3B723C8A287FF81800822B7C /* TagCVC.swift */,
3B723C902880037100822B7C /* ReviewPhotoCVC.swift */,
3BDE7F282882054200EE7F47 /* ReviewEmptyViewCVC.swift */,
3B3DCF492882B55D009256BD /* Review */,
3B3DCF482882B540009256BD /* BlogReview */,
3B3DCF472882B534009256BD /* Common */,
);
path = Cells;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class ReviewCVC: UICollectionViewCell, UICollectionViewRegisterable {
}
}

var setEnumValue = 0
var layoutEnumValue = 0

let width = UIScreen.main.bounds.width

var clickedEvent: ((Int) -> Void)?
var isFolded: Bool = true
// MARK: - UI Components

private var nameLabel: UILabel = {
Expand Down Expand Up @@ -83,6 +84,16 @@ class ReviewCVC: UICollectionViewCell, UICollectionViewRegisterable {
return view
}()

lazy var moreTapButton: UIButton = {
let button = UIButton()
button.backgroundColor = .clear
button.press {
guard let index = self.getIndexPath() else { return }
self.clickedEvent?(index)
}
return button
}()

// MARK: - Life Cycle Part

override init(frame: CGRect) {
Expand Down Expand Up @@ -121,7 +132,7 @@ extension ReviewCVC {

func setDefaultLayout() {
contentView.addSubviews(nameLabel, starView, tagCV,
reviewPhotoCV, reviewContents, reviewSeperatorView)
reviewPhotoCV, reviewContents, reviewSeperatorView,moreTapButton)

let width = UIScreen.main.bounds.width

Expand Down Expand Up @@ -166,10 +177,19 @@ extension ReviewCVC {
make.bottom.equalToSuperview().offset(-28)
make.width.equalTo(width - 40)
}

moreTapButton.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-28)
make.trailing.equalToSuperview().offset(-30)
make.width.equalTo(width - 40)
make.height.equalToSuperview()
}


}

func setLayout() {
switch setEnumValue {
switch layoutEnumValue {
case 0:
setLayoutWithImageAndContents()
case 1:
Expand Down Expand Up @@ -253,15 +273,59 @@ extension ReviewCVC {
}
}

func setData(reviewData: ReviewDataModel) {
func setData(reviewData: ReviewDataModel,
text: String,
isFoldRequired: Bool,
expanded: Bool) {
nameLabel.text = reviewData.reviewer
nameLabel.sizeToFit()
starView.rate = CGFloat(reviewData.starLate)
self.cellViewModel = reviewData
reviewContents.text = reviewData.reviewContents
reviewContents.text = text
reviewContents.sizeToFit()

if isFoldRequired {
moreTapButton.isHidden = false
} else {
moreTapButton.isHidden = true
}

if !expanded {
setPartContentsAttributes()
} else {
let attributedString = NSMutableAttributedString(string: text)
reviewContents.attributedText = attributedString
}

self.contentView.layoutIfNeeded()
}

private func getIndexPath() -> Int? {
guard let superView = self.superview as? UICollectionView else {
return nil
}
let indexPath = superView.indexPath(for: self)
return indexPath?.row
}

func setPartContentsAttributes() {
var textCount = 0
var length = 0
if reviewContents.text?.count ?? 0 < 3 {
textCount = 3
length = reviewContents.text?.count ?? 0
} else {
textCount = reviewContents.text?.count ?? 0
length = 3
}
let fullText = reviewContents.text
let range = NSRange(location: textCount - 3, length: length)

let attributedString = NSMutableAttributedString(string: fullText ?? "")
attributedString.addAttribute(.font, value: UIFont.NotoRegular(size: 12), range: range)
attributedString.addAttribute(.foregroundColor, value: UIColor.helfmeGray2, range: range)
reviewContents.attributedText = attributedString
}
}

extension ReviewCVC: UICollectionViewDelegate {
Expand Down
Loading