ReaderHive/ReaderHive/Class/Home/V/NRHomeNovelMustReadTodayView.swift
2025-12-08 16:46:19 +08:00

87 lines
2.7 KiB
Swift

//
// NRHomeNovelMustReadTodayView.swift
// ReaderHive
//
// Created by on 2025/11/24.
//
import UIKit
import SnapKit
import YYCategories
class NRHomeNovelMustReadTodayView: NRHomeNovelHeaderContentView {
var dataArr: [NRNovelModel] = [] {
didSet {
self.collectionView.reloadData()
}
}
lazy var collectionViewLayout: UICollectionViewFlowLayout = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.itemSize = .init(width: 316, height: 174)
layout.minimumLineSpacing = 16
return layout
}()
lazy var collectionView: NRCollectionView = {
let collectionView = NRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.showsHorizontalScrollIndicator = false
collectionView.contentInset = .init(top: 0, left: 16, bottom: 0, right: 16)
collectionView.register(NRHomeNovelMustReadTodayCell.self, forCellWithReuseIdentifier: "cell")
return collectionView
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.titleLabel.text = "Must-Read Today".localized
nr_setupUI()
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension NRHomeNovelMustReadTodayView {
private func nr_setupUI() {
contentView.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.right.top.equalToSuperview()
make.bottom.equalToSuperview()
make.height.equalTo(self.collectionViewLayout.itemSize.height)
}
}
}
//MARK: UICollectionViewDelegate UICollectionViewDataSource
extension NRHomeNovelMustReadTodayView: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! NRHomeNovelMustReadTodayCell
cell.model = self.dataArr[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.dataArr.count
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = NRNovelDetailViewController()
vc.novelId = dataArr[indexPath.row].id ?? ""
self.viewController?.navigationController?.pushViewController(vc, animated: true)
}
}