Fix home account switch layout crash

This commit is contained in:
2026-07-07 14:34:31 +08:00
parent 234142ed69
commit b3906da0e2
3 changed files with 31 additions and 8 deletions

View File

@ -35,8 +35,8 @@ enum HomeCollectionLayoutBuilder {
/// Compositional Layout section
static func makeLayout(sections: [HomeCollectionSection]) -> UICollectionViewCompositionalLayout {
UICollectionViewCompositionalLayout { sectionIndex, environment in
guard sectionIndex < sections.count else { return nil }
switch sections[sectionIndex] {
let section = sectionIndex < sections.count ? sections[sectionIndex] : .commonApps
switch section {
case .workStatus:
return fullWidthSection(height: AppSpacing.formRowHeight)
case .locationReport:

View File

@ -9,6 +9,8 @@ import UIKit
/// Tab
final class HomeViewController: BaseViewController {
private static let fallbackCellReuseIdentifier = "HomeFallbackCell"
private let viewModel = HomeViewModel()
private let homeAPI = NetworkServices.shared.homeAPI
@ -117,6 +119,10 @@ final class HomeViewController: BaseViewController {
private func registerCollectionCells() {
collectionView.register(HomeWorkStatusCell.self, forCellWithReuseIdentifier: HomeWorkStatusCell.reuseIdentifier)
collectionView.register(
UICollectionViewCell.self,
forCellWithReuseIdentifier: Self.fallbackCellReuseIdentifier
)
collectionView.register(
HomeLocationReportCell.self,
forCellWithReuseIdentifier: HomeLocationReportCell.reuseIdentifier
@ -138,7 +144,18 @@ final class HomeViewController: BaseViewController {
let dataSource = UICollectionViewDiffableDataSource<HomeCollectionSection, HomeCollectionItem>(
collectionView: collectionView
) { [weak self] collectionView, indexPath, item in
guard let self else { return UICollectionViewCell() }
guard let self else {
return collectionView.dequeueReusableCell(
withReuseIdentifier: Self.fallbackCellReuseIdentifier,
for: indexPath
)
}
guard indexPath.section < self.currentSections.count else {
return collectionView.dequeueReusableCell(
withReuseIdentifier: Self.fallbackCellReuseIdentifier,
for: indexPath
)
}
let section = self.currentSections[indexPath.section]
switch (section, item) {
case (.workStatus, .workStatus):
@ -217,14 +234,15 @@ final class HomeViewController: BaseViewController {
return cell
default:
return UICollectionViewCell()
return collectionView.dequeueReusableCell(
withReuseIdentifier: Self.fallbackCellReuseIdentifier,
for: indexPath
)
}
}
dataSource.supplementaryViewProvider = { collectionView, kind, indexPath in
guard kind == UICollectionView.elementKindSectionHeader,
indexPath.section < self.currentSections.count,
self.currentSections[indexPath.section] == .commonApps else {
guard kind == UICollectionView.elementKindSectionHeader else {
return nil
}
let header = collectionView.dequeueReusableSupplementaryView(
@ -232,7 +250,9 @@ final class HomeViewController: BaseViewController {
withReuseIdentifier: HomeSectionHeaderView.reuseIdentifier,
for: indexPath
) as! HomeSectionHeaderView
header.apply(title: "常用应用")
let title = indexPath.section < self.currentSections.count
&& self.currentSections[indexPath.section] == .commonApps ? "常用应用" : ""
header.apply(title: title)
return header
}

View File

@ -194,11 +194,14 @@ final class ProfileInfoRowView: UIControl {
rightStack.axis = .vertical
rightStack.alignment = .trailing
rightStack.spacing = 4
rightStack.isUserInteractionEnabled = false
rightStack.addArrangedSubview(stackNameLabel)
rightStack.addArrangedSubview(stackTypeTag)
rightStack.isHidden = true
badgeContainer.isUserInteractionEnabled = false
divider.backgroundColor = UIColor(hex: 0xE5E7EB)
divider.isUserInteractionEnabled = false
addSubview(titleLabel)
addSubview(valueLabel)