Refactor home to single collection view and add all-functions customization.
Replace scroll/stack layout with one UICollectionView, fix grid column math and Diffable item IDs so location report and quick actions render, and add the customizable all-functions page with persistence and tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
193
suixinkan/UI/Home/Views/HomeCollectionCells.swift
Normal file
193
suixinkan/UI/Home/Views/HomeCollectionCells.swift
Normal file
@ -0,0 +1,193 @@
|
||||
//
|
||||
// HomeCollectionCells.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 首页在线状态卡片 cell。
|
||||
final class HomeWorkStatusCell: UICollectionViewCell {
|
||||
|
||||
static let reuseIdentifier = "HomeWorkStatusCell"
|
||||
|
||||
let cardView = HomeWorkStatusCardView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
contentView.addSubview(cardView)
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(isOnline: Bool, countdownText: String, reminderMinutes: Int) {
|
||||
cardView.apply(isOnline: isOnline, countdownText: countdownText, reminderMinutes: reminderMinutes)
|
||||
}
|
||||
}
|
||||
|
||||
/// 首页位置上报卡片 cell。
|
||||
final class HomeLocationReportCell: UICollectionViewCell {
|
||||
|
||||
static let reuseIdentifier = "HomeLocationReportCell"
|
||||
|
||||
let cardView = HomeLocationReportCardView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
contentView.addSubview(cardView)
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(address: String, isReporting: Bool) {
|
||||
cardView.apply(address: address, isReporting: isReporting)
|
||||
}
|
||||
}
|
||||
|
||||
/// 首页快捷操作 cell。
|
||||
final class HomeQuickActionsCell: UICollectionViewCell {
|
||||
|
||||
static let reuseIdentifier = "HomeQuickActionsCell"
|
||||
|
||||
let cardView = HomeQuickActionsView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
contentView.addSubview(cardView)
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(isOnline: Bool) {
|
||||
cardView.apply(isOnline: isOnline)
|
||||
}
|
||||
}
|
||||
|
||||
/// 首页门店信息 cell。
|
||||
final class HomeStoreCell: UICollectionViewCell {
|
||||
|
||||
static let reuseIdentifier = "HomeStoreCell"
|
||||
|
||||
let cardView = HomeStoreCardView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
contentView.addSubview(cardView)
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(store: StoreItem) {
|
||||
cardView.apply(store: store)
|
||||
}
|
||||
}
|
||||
|
||||
/// 首页常用应用菜单 cell。
|
||||
final class HomeMenuCell: UICollectionViewCell {
|
||||
|
||||
static let reuseIdentifier = "HomeMenuCell"
|
||||
|
||||
private let cardView = UIView()
|
||||
private let iconView = UIImageView()
|
||||
private let titleLabel = UILabel()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
setupUI()
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(menu: HomeMenuItem) {
|
||||
iconView.image = UIImage(systemName: menu.iconName)
|
||||
titleLabel.text = menu.title
|
||||
}
|
||||
|
||||
private func setupUI() {
|
||||
contentView.backgroundColor = .clear
|
||||
|
||||
cardView.backgroundColor = .white
|
||||
cardView.layer.cornerRadius = AppRadius.md
|
||||
cardView.clipsToBounds = true
|
||||
|
||||
iconView.tintColor = AppColor.primary
|
||||
iconView.contentMode = .scaleAspectFit
|
||||
|
||||
titleLabel.font = .app(.body)
|
||||
titleLabel.textColor = AppColor.textSecondary
|
||||
titleLabel.textAlignment = .center
|
||||
titleLabel.numberOfLines = 2
|
||||
|
||||
contentView.addSubview(cardView)
|
||||
cardView.addSubview(iconView)
|
||||
cardView.addSubview(titleLabel)
|
||||
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
iconView.snp.makeConstraints { make in
|
||||
make.top.equalToSuperview().offset(AppSpacing.sm)
|
||||
make.centerX.equalToSuperview()
|
||||
make.width.height.equalTo(24)
|
||||
}
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.top.equalTo(iconView.snp.bottom).offset(AppSpacing.sm)
|
||||
make.leading.trailing.equalToSuperview().inset(AppSpacing.xxs)
|
||||
make.bottom.lessThanOrEqualToSuperview().inset(AppSpacing.xs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 首页分区标题 supplementary view。
|
||||
final class HomeSectionHeaderView: UICollectionReusableView {
|
||||
|
||||
static let reuseIdentifier = "HomeSectionHeaderView"
|
||||
|
||||
private let titleLabel = UILabel()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
titleLabel.font = .app(.title)
|
||||
titleLabel.textColor = AppColor.textPrimary
|
||||
addSubview(titleLabel)
|
||||
titleLabel.snp.makeConstraints { make in
|
||||
make.leading.trailing.bottom.equalToSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(title: String) {
|
||||
titleLabel.text = title
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user