116 lines
3.7 KiB
Swift
116 lines
3.7 KiB
Swift
//
|
|
// FAStoreVipView.swift
|
|
// Fableon
|
|
//
|
|
// Created by 湖北秦九 on 2025/10/27.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class FAStoreVipView: UIView {
|
|
|
|
var dataArr: [FAPayItem] = [] {
|
|
didSet {
|
|
collectionView.reloadData()
|
|
}
|
|
}
|
|
|
|
var shortPlayId: String?
|
|
var videoId: String?
|
|
|
|
var buyFinishHandle: (() -> Void)?
|
|
|
|
|
|
private lazy var collectionViewLayout: UICollectionViewCompositionalLayout = {
|
|
|
|
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
|
|
|
|
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(110)), subitems: [item])
|
|
|
|
let layoutSection = NSCollectionLayoutSection(group: group)
|
|
layoutSection.interGroupSpacing = 14
|
|
layoutSection.contentInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16)
|
|
|
|
|
|
let config = UICollectionViewCompositionalLayoutConfiguration()
|
|
|
|
let layout = UICollectionViewCompositionalLayout(section: layoutSection)
|
|
layout.configuration = config
|
|
|
|
return layout
|
|
}()
|
|
|
|
private lazy var collectionView: FACollectionView = {
|
|
let collectionView = FACollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
|
|
collectionView.delegate = self
|
|
collectionView.dataSource = self
|
|
collectionView.isScrollEnabled = false
|
|
collectionView.addObserver(self, forKeyPath: "contentSize", context: nil)
|
|
collectionView.register(FAStoreVipCell.self, forCellWithReuseIdentifier: "cell")
|
|
return collectionView
|
|
}()
|
|
|
|
deinit {
|
|
collectionView.removeObserver(self, forKeyPath: "contentSize")
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
fa_setupLayout()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
|
if keyPath == "contentSize" {
|
|
let height = self.collectionView.contentSize.height + 1
|
|
self.collectionView.snp.updateConstraints { make in
|
|
make.height.equalTo(height)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension FAStoreVipView {
|
|
|
|
private func fa_setupLayout() {
|
|
addSubview(collectionView)
|
|
|
|
collectionView.snp.makeConstraints { make in
|
|
make.edges.equalToSuperview()
|
|
make.height.equalTo(1)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//MARK: UICollectionViewDelegate UICollectionViewDataSource
|
|
extension FAStoreVipView: UICollectionViewDelegate, UICollectionViewDataSource {
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! FAStoreVipCell
|
|
cell.item = self.dataArr[indexPath.row]
|
|
return cell
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
return dataArr.count
|
|
}
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let model = self.dataArr[indexPath.row]
|
|
|
|
FAIapManager.manager.start(model: model, shortPlayId: self.shortPlayId, videoId: self.videoId) { [weak self] finish in
|
|
guard let self = self else { return }
|
|
if finish {
|
|
FALogin.manager.requestUserInfo(completer: nil)
|
|
self.buyFinishHandle?()
|
|
}
|
|
}
|
|
}
|
|
}
|