fix: optimize report detail evidence UI
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user