Skip to content

Commit

Permalink
[Feat] sopt-makers#360 - 파트 차트 랭킹 데이터 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Apr 1, 2024
1 parent 5aec792 commit 6e4c4b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,23 @@ extension STPartChartRectangleView {
}
}

private func updateLayout() {
rectangleView.snp.updateConstraints { make in
make.height.equalTo(self.calculateRectangleViewHeight())
}
}

private func calculateRectangleViewHeight() -> CGFloat {
return 27.f * (7 - rank).f
}
}

extension STPartChartRectangleView {
public func setData(rank: Int, partName: String) {
print(rank)
self.rank = rank
self.partName = partName
self.setUI()
self.updateLayout()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ extension PartRankingChartCVC {
// MARK: - Methods

extension PartRankingChartCVC {

public func setData(model: RankingChartModel) {
let models = model.ranking
self.models = models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public class PartRankingVC: UIViewController, PartRankingViewControllable {
self.setDataSource()

// TODO: 제거
applySnapshot(model: [.init(username: "a", score: 1, sentence: "test"),
applySnapshot(model: [.init(username: "a", score: 4, sentence: "test"),
.init(username: "b", score: 1, sentence: "test"),
.init(username: "c", score: 1, sentence: "test"),
.init(username: "d", score: 1, sentence: "test")]
.init(username: "c", score: 3, sentence: "test"),
.init(username: "d", score: 2, sentence: "test")]
)
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ extension PartRankingVC {
guard let rankingListCell = collectionView.dequeueReusableCell(withReuseIdentifier: RankingListCVC.className, for: indexPath) as? RankingListCVC,
let rankingListCellModel = itemIdentifier as? RankingModel else { return UICollectionViewCell() }
rankingListCell.setData(model: rankingListCellModel,
rank: indexPath.row + 1 + 3)
rank: indexPath.row+1)

return rankingListCell
}
Expand All @@ -171,12 +171,9 @@ extension PartRankingVC {
func applySnapshot(model: [RankingModel]) {
var snapshot = NSDiffableDataSourceSnapshot<RankingSection, AnyHashable>()
snapshot.appendSections([.chart, .list])
guard model.count >= 4 else { return }
guard let chartCellModels = Array(model[0...2]) as? [RankingModel],
let rankingListModel = Array(model[3...model.count-1]) as? [RankingModel] else { return }
let chartCellModel = RankingChartModel.init(ranking: chartCellModels)
let chartCellModel = RankingChartModel.init(ranking: model)
snapshot.appendItems([chartCellModel], toSection: .chart)
snapshot.appendItems(rankingListModel, toSection: .list)
snapshot.appendItems(model, toSection: .list)
dataSource.apply(snapshot, animatingDifferences: false)
self.view.setNeedsLayout()
}
Expand Down

0 comments on commit 6e4c4b8

Please sign in to comment.