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 /// Compositional Layout section
static func makeLayout(sections: [HomeCollectionSection]) -> UICollectionViewCompositionalLayout { static func makeLayout(sections: [HomeCollectionSection]) -> UICollectionViewCompositionalLayout {
UICollectionViewCompositionalLayout { sectionIndex, environment in UICollectionViewCompositionalLayout { sectionIndex, environment in
guard sectionIndex < sections.count else { return nil } let section = sectionIndex < sections.count ? sections[sectionIndex] : .commonApps
switch sections[sectionIndex] { switch section {
case .workStatus: case .workStatus:
return fullWidthSection(height: AppSpacing.formRowHeight) return fullWidthSection(height: AppSpacing.formRowHeight)
case .locationReport: case .locationReport:

View File

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

View File

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