fix: optimize report detail evidence UI

This commit is contained in:
2026-07-09 11:11:21 +08:00
parent 939295d74a
commit 9b92d81902
2 changed files with 340 additions and 111 deletions

View File

@ -30,10 +30,20 @@ final class AllFunctionsViewController: BaseViewController {
}
}
///
private struct AllFunctionListItem: Hashable {
let section: AllFunctionSection
let menu: HomeMenuItem
var actionStyle: AllFunctionMenuCell.ActionStyle {
section.actionStyle
}
}
private let viewModel = AllFunctionsViewModel()
private let collectionView: UICollectionView
private var dataSource: UICollectionViewDiffableDataSource<AllFunctionSection, HomeMenuItem>!
private var dataSource: UICollectionViewDiffableDataSource<AllFunctionSection, AllFunctionListItem>!
private var hasAppliedInitialSnapshot = false
init() {
@ -104,30 +114,35 @@ final class AllFunctionsViewController: BaseViewController {
@MainActor
private func applyViewModel(animated: Bool) {
var snapshot = NSDiffableDataSourceSnapshot<AllFunctionSection, HomeMenuItem>()
var snapshot = NSDiffableDataSourceSnapshot<AllFunctionSection, AllFunctionListItem>()
snapshot.appendSections([.common, .more])
snapshot.appendItems(viewModel.commonMenus, toSection: .common)
snapshot.appendItems(viewModel.moreMenus, toSection: .more)
snapshot.appendItems(
viewModel.commonMenus.map { AllFunctionListItem(section: .common, menu: $0) },
toSection: .common
)
snapshot.appendItems(
viewModel.moreMenus.map { AllFunctionListItem(section: .more, menu: $0) },
toSection: .more
)
dataSource.apply(snapshot, animatingDifferences: animated)
hasAppliedInitialSnapshot = true
}
private func makeDataSource() -> UICollectionViewDiffableDataSource<AllFunctionSection, HomeMenuItem> {
let dataSource = UICollectionViewDiffableDataSource<AllFunctionSection, HomeMenuItem>(
private func makeDataSource() -> UICollectionViewDiffableDataSource<AllFunctionSection, AllFunctionListItem> {
let dataSource = UICollectionViewDiffableDataSource<AllFunctionSection, AllFunctionListItem>(
collectionView: collectionView
) { [weak self] collectionView, indexPath, menu in
) { [weak self] collectionView, indexPath, item in
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: AllFunctionMenuCell.reuseIdentifier,
for: indexPath
) as! AllFunctionMenuCell
guard let section = AllFunctionSection(rawValue: indexPath.section) else { return cell }
cell.apply(menu: menu, actionStyle: section.actionStyle)
cell.apply(menu: item.menu, actionStyle: item.actionStyle)
cell.onActionTap = {
switch section {
switch item.section {
case .common:
self?.viewModel.removeFromCommon(menu)
self?.viewModel.removeFromCommon(item.menu)
case .more:
self?.viewModel.addToCommon(menu)
self?.viewModel.addToCommon(item.menu)
}
}
return cell