BeeReel/BeeReel/Class/Home/View/Spotlight/BRSpotlightHotMainCell.swift
2025-06-30 18:18:27 +08:00

106 lines
3.5 KiB
Swift

//
// BRSpotlightHotMainCell.swift
// BeeReel
//
// Created by on 2025/6/27.
//
import UIKit
class BRSpotlightHotMainCell: BRSpotlightMainBaseCell {
override var moduleItem: BRHomeModuleItem? {
didSet {
UIView.performWithoutAnimation { [weak self] in
self?.collectionView.reloadData()
}
self.collectionView.performBatchUpdates(nil) { [weak self] _ in
guard let self = self else { return }
let height = moduleItem?.br_cellHeight ?? 0
let contentHeight = self.collectionView.contentSize.height
if height != contentHeight {
self.collectionView.snp.updateConstraints { make in
make.height.equalTo(contentHeight + 1)
}
moduleItem?.br_cellHeight = contentHeight
self.br_tableView?.reloadData()
}
}
}
}
private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
let width = floor((UIScreen.width - 30 - 10) / 2)
let layout = UICollectionViewFlowLayout()
layout.itemSize = .init(width: width, height: 222)
layout.minimumInteritemSpacing = 10
layout.minimumLineSpacing = 10
layout.sectionInset = .init(top: 0, left: 15, bottom: 0, right: 15)
return layout
}()
private lazy var collectionView: BRCollectionView = {
let collectionView = BRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.isScrollEnabled = false
collectionView.register(BRSpotlightHotCell.self, forCellWithReuseIdentifier: "cell")
return collectionView
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
br_setupUI()
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension BRSpotlightHotMainCell {
private func br_setupUI() {
containerView.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.edges.equalToSuperview()
make.height.equalTo(1)
}
}
}
//MARK: -------------- UICollectionViewDelegate UICollectionViewDataSource --------------
extension BRSpotlightHotMainCell: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! BRSpotlightHotCell
cell.model = self.moduleItem?.list?[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.moduleItem?.list?.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let model = self.moduleItem?.list?[indexPath.row]
let vc = BRVideoDetailViewController()
vc.shortPlayId = model?.short_play_id
self.viewController?.navigationController?.pushViewController(vc, animated: true)
}
}