-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Fix] #260 - 무한 스크롤 과정에서 발생한 메모리 사용량 개선 및 레이아웃 계산 최적화 #261
Changes from all commits
0c31761
5ec281f
90d8764
304aa05
beea15f
8c7d505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ final class BakeryCommonCollectionViewCell: UICollectionViewCell { | |
|
||
private var breadTypeTag: [String] = [] | ||
private var ingredientList: [BakeryCommonListResponseDTO] = [] | ||
|
||
private var itemSizeCache: [Int: CGSize] = [:] | ||
|
||
// MARK: - UI Property | ||
|
||
private let markStackView = MarkStackView() | ||
|
@@ -32,13 +33,14 @@ final class BakeryCommonCollectionViewCell: UICollectionViewCell { | |
|
||
override func prepareForReuse() { | ||
super.prepareForReuse() | ||
|
||
ingredientList = [] | ||
bakeryImage.kf.cancelDownloadTask() | ||
bakeryImage.image = nil | ||
itemSizeCache.removeAll() | ||
} | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: .zero) | ||
|
||
super.init(frame: frame) | ||
setLayout() | ||
setUI() | ||
setRegistration() | ||
|
@@ -58,7 +60,6 @@ final class BakeryCommonCollectionViewCell: UICollectionViewCell { | |
$0.top.equalToSuperview().offset(24) | ||
$0.leading.equalToSuperview().inset(24) | ||
$0.bottom.equalToSuperview().inset(24) | ||
|
||
} | ||
|
||
contentView.addSubview(bookmarkCount) | ||
|
@@ -123,45 +124,53 @@ final class BakeryCommonCollectionViewCell: UICollectionViewCell { | |
} | ||
|
||
func configureReviewsUI() { | ||
|
||
bookmarkCount.removeFromSuperview() | ||
} | ||
|
||
func configureCellUI<T: BakeryListProtocol>(data: T) { | ||
|
||
bakeryTitle.setLineHeight(by: 1.05, with: data.name) | ||
bakeryTitle.lineBreakMode = .byTruncatingTail | ||
|
||
bookmarkCount.configureHomeCell(count: data.bookmarkCount) | ||
bookmarkCount.setContentHuggingPriority(UILayoutPriority(751), for: .horizontal) | ||
bookmarkCount.setContentCompressionResistancePriority(UILayoutPriority(751), for: .horizontal) | ||
|
||
guard let url = URL(string: data.picture) else { return } | ||
bakeryImage.kf.setImage(with: url, placeholder: UIImage.loading_small) | ||
|
||
regionStackView.configureListUI(text: data.station) | ||
markStackView.getMarkStatus(data.isHACCP, data.isVegan, data.isNonGMO) | ||
|
||
breadTypeTag = [] | ||
data.breadTypeList.forEach { | ||
breadTypeTag.append($0.toString()) | ||
} | ||
collectionView.reloadData() | ||
setupCellUI(name: data.name, | ||
pictureURL: data.picture, | ||
station: data.station, | ||
isHACCP: data.isHACCP, | ||
isVegan: data.isVegan, | ||
isNonGMO: data.isNonGMO, | ||
breadTypeList: data.breadTypeList) | ||
} | ||
|
||
func configureCellUI(data: MyReviewsResponseDTO) { | ||
bakeryTitle.setLineHeight(by: 1.05, with: data.name) | ||
setupCellUI(name: data.name, | ||
pictureURL: data.picture, | ||
station: data.station, | ||
isHACCP: data.isHACCP, | ||
isVegan: data.isVegan, | ||
isNonGMO: data.isNonGMO, | ||
breadTypeList: data.breadTypeList) | ||
} | ||
|
||
private func setupCellUI(name: String, pictureURL: String, station: String, isHACCP: Bool, isVegan: Bool, isNonGMO: Bool, breadTypeList: [BreadType]) { | ||
bakeryTitle.setLineHeight(by: 1.05, with: name) | ||
bakeryTitle.lineBreakMode = .byTruncatingTail | ||
|
||
guard let url = URL(string: data.picture) else { return } | ||
bakeryImage.kf.setImage(with: url, placeholder: UIImage.loading_small) | ||
|
||
regionStackView.configureListUI(text: data.station) | ||
markStackView.getMarkStatus(data.isHACCP, data.isVegan, data.isNonGMO) | ||
|
||
breadTypeTag = [] | ||
data.breadTypeList.forEach { | ||
breadTypeTag.append($0.toString()) | ||
} | ||
guard let url = URL(string: pictureURL) else { return } | ||
bakeryImage.kf.setImage( | ||
with: url, | ||
placeholder: UIImage.loading_small, | ||
options: [ | ||
.processor(DownsamplingImageProcessor(size: CGSize(width: 86, height: 86))), | ||
.scaleFactor(UIScreen.main.scale), | ||
.cacheOriginalImage | ||
]) | ||
|
||
regionStackView.configureListUI(text: station) | ||
markStackView.getMarkStatus(isHACCP, isVegan, isNonGMO) | ||
|
||
breadTypeTag = breadTypeList.map { $0.toString() } | ||
itemSizeCache.removeAll() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 itemSizeCache도 Cell마다 인스턴스로 갖고 있기 보다는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 한 곳에서 관리하는 것도 좋은 방법인 것 같슴돠 !!! 이 부분도 같이 고민하는걸로 |
||
collectionView.reloadData() | ||
} | ||
} | ||
|
@@ -170,7 +179,6 @@ final class BakeryCommonCollectionViewCell: UICollectionViewCell { | |
|
||
extension BakeryCommonCollectionViewCell { | ||
private func setRegistration() { | ||
|
||
collectionView.register(cell: DescriptionCollectionViewCell.self) | ||
} | ||
} | ||
|
@@ -179,12 +187,10 @@ extension BakeryCommonCollectionViewCell { | |
|
||
extension BakeryCommonCollectionViewCell: UICollectionViewDataSource { | ||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
|
||
return breadTypeTag.count | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
|
||
let cell: DescriptionCollectionViewCell = collectionView.dequeueReusableCell(for: indexPath) | ||
cell.cellColor = .sub | ||
cell.configureTagTitle(self.breadTypeTag[indexPath.item]) | ||
|
@@ -196,9 +202,15 @@ extension BakeryCommonCollectionViewCell: UICollectionViewDataSource { | |
|
||
extension BakeryCommonCollectionViewCell: UICollectionViewDelegateFlowLayout { | ||
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | ||
let tagTitle = breadTypeTag[indexPath.item] | ||
|
||
guard let cachedSize = itemSizeCache[tagTitle.count] else { | ||
let itemSize = tagTitle.size(withAttributes: [NSAttributedString.Key.font: UIFont.captionM2]) | ||
let finalSize = CGSize(width: itemSize.width + 12, height: itemSize.height) | ||
itemSizeCache[tagTitle.count] = finalSize | ||
return finalSize | ||
} | ||
|
||
let tagTitle = self.breadTypeTag[indexPath.item] | ||
let itemSize = tagTitle.size(withAttributes: [NSAttributedString.Key.font: UIFont.captionM2!]) | ||
return CGSize(width: itemSize.width + 12, height: itemSize.height) | ||
return cachedSize | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아주 필요한 기능을 알잘딱깔센으로다가 잘 넣고 있군요 !!!!
코드 보다가 문득 든 생각이 ... 요 DownsamplingImageProcessor 녀석을 셀마다 인스턴스로 만들지 않고
collectionview마다 만들거나 더 좋은 방법으로 재사용할 수는 없을까에 대한 생각이 들었습니다 !!
셀마다 주입하는건 어떨지 ... 아니면 kingfisher extension으로 어떻게 할 방법은 없을지 고민해보죠 !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 좋습니당 :)