SynthReel/SynthReel/Class/Home/V/SRHomeBingeWorthyView.swift
2025-12-10 10:23:22 +08:00

76 lines
2.5 KiB
Swift

//
// SRHomeBingeWorthyView.swift
// SynthReel
//
// Created by on 2025/11/17.
// Copyright © 2025 SR. All rights reserved.
//
import UIKit
import SnapKit
class SRHomeBingeWorthyView: SRHomeModuleView {
var dataArr: [SRShortModel]? {
didSet {
collectionView.reloadData()
}
}
lazy var collectionViewLayout: UICollectionViewFlowLayout = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumLineSpacing = 12
layout.itemSize = .init(width: 320, height: 192)
return layout
}()
lazy var collectionView: SRCollectionView = {
let collectionView = SRCollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.showsHorizontalScrollIndicator = false
collectionView.contentInset = .init(top: 0, left: 15, bottom: 0, right: 15)
collectionView.register(SRHomeBingeWorthyCell.self, forCellWithReuseIdentifier: "cell")
return collectionView
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.titleLabel.text = "Binge-Worthy".localized
addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.top.equalTo(button.snp.bottom).offset(6)
make.height.equalTo(collectionViewLayout.itemSize.height)
}
}
@MainActor required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//MARK: UICollectionViewDataSource UICollectionViewDelegate
extension SRHomeBingeWorthyView: UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SRHomeBingeWorthyCell
cell.model = self.dataArr?[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.dataArr?.count ?? 0
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
self.didSelectedShort?(self.dataArr?[indexPath.row])
}
}