完善任务流程、键盘适配与页面交互
This commit is contained in:
@ -65,7 +65,8 @@ final class AllFunctionsViewController: BaseViewController {
|
||||
|
||||
collectionView.backgroundColor = .clear
|
||||
collectionView.alwaysBounceVertical = true
|
||||
collectionView.allowsSelection = false
|
||||
collectionView.allowsSelection = true
|
||||
collectionView.delegate = self
|
||||
collectionView.contentInset = UIEdgeInsets(
|
||||
top: AppSpacing.xs,
|
||||
left: 0,
|
||||
@ -131,20 +132,12 @@ final class AllFunctionsViewController: BaseViewController {
|
||||
private func makeDataSource() -> UICollectionViewDiffableDataSource<AllFunctionSection, AllFunctionListItem> {
|
||||
let dataSource = UICollectionViewDiffableDataSource<AllFunctionSection, AllFunctionListItem>(
|
||||
collectionView: collectionView
|
||||
) { [weak self] collectionView, indexPath, item in
|
||||
) { collectionView, indexPath, item in
|
||||
let cell = collectionView.dequeueReusableCell(
|
||||
withReuseIdentifier: AllFunctionMenuCell.reuseIdentifier,
|
||||
for: indexPath
|
||||
) as! AllFunctionMenuCell
|
||||
cell.apply(menu: item.menu, actionStyle: item.actionStyle)
|
||||
cell.onActionTap = {
|
||||
switch item.section {
|
||||
case .common:
|
||||
self?.viewModel.removeFromCommon(item.menu)
|
||||
case .more:
|
||||
self?.viewModel.addToCommon(item.menu)
|
||||
}
|
||||
}
|
||||
return cell
|
||||
}
|
||||
|
||||
@ -214,6 +207,21 @@ final class AllFunctionsViewController: BaseViewController {
|
||||
}
|
||||
}
|
||||
|
||||
extension AllFunctionsViewController: UICollectionViewDelegate {
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
guard let item = dataSource.itemIdentifier(for: indexPath) else { return }
|
||||
collectionView.deselectItem(at: indexPath, animated: true)
|
||||
|
||||
switch item.section {
|
||||
case .common:
|
||||
viewModel.removeFromCommon(item.menu)
|
||||
case .more:
|
||||
viewModel.addToCommon(item.menu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 全部功能页分区标题。
|
||||
private final class AllFunctionSectionHeaderView: UICollectionReusableView {
|
||||
|
||||
|
||||
@ -6,24 +6,29 @@
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 全部功能页菜单卡片,支持右上角添加或移除操作。
|
||||
/// 全部功能页菜单卡片,整张卡片响应选择,右上角图标仅展示添加或移除状态。
|
||||
final class AllFunctionMenuCell: UICollectionViewCell {
|
||||
|
||||
static let reuseIdentifier = "AllFunctionMenuCell"
|
||||
|
||||
/// 卡片右上角展示的操作状态。
|
||||
enum ActionStyle {
|
||||
case none
|
||||
case add
|
||||
case remove
|
||||
}
|
||||
|
||||
var onActionTap: (() -> Void)?
|
||||
|
||||
private let cardView = UIView()
|
||||
private let contentStackView = UIStackView()
|
||||
private let iconView = UIImageView()
|
||||
private let titleLabel = UILabel()
|
||||
private let actionButton = UIButton(type: .system)
|
||||
private let actionImageView = UIImageView()
|
||||
|
||||
override var isHighlighted: Bool {
|
||||
didSet {
|
||||
cardView.alpha = isHighlighted ? 0.72 : 1
|
||||
}
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
@ -35,26 +40,29 @@ final class AllFunctionMenuCell: UICollectionViewCell {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
onActionTap = nil
|
||||
}
|
||||
|
||||
/// 更新菜单内容、操作状态及整张卡片的无障碍语义。
|
||||
func apply(menu: HomeMenuItem, actionStyle: ActionStyle) {
|
||||
iconView.image = UIImage(systemName: menu.iconName)
|
||||
titleLabel.text = menu.title
|
||||
accessibilityLabel = menu.title
|
||||
|
||||
switch actionStyle {
|
||||
case .none:
|
||||
actionButton.isHidden = true
|
||||
actionImageView.isHidden = true
|
||||
accessibilityTraits = []
|
||||
accessibilityHint = nil
|
||||
case .add:
|
||||
actionButton.isHidden = false
|
||||
actionButton.setImage(UIImage(systemName: "plus.circle.fill"), for: .normal)
|
||||
actionButton.tintColor = AppColor.primary
|
||||
actionImageView.isHidden = false
|
||||
actionImageView.image = UIImage(systemName: "plus.circle.fill")
|
||||
actionImageView.tintColor = AppColor.primary
|
||||
accessibilityTraits = .button
|
||||
accessibilityHint = "添加到常用应用"
|
||||
case .remove:
|
||||
actionButton.isHidden = false
|
||||
actionButton.setImage(UIImage(systemName: "minus.circle.fill"), for: .normal)
|
||||
actionButton.tintColor = AppColor.danger
|
||||
actionImageView.isHidden = false
|
||||
actionImageView.image = UIImage(systemName: "minus.circle.fill")
|
||||
actionImageView.tintColor = AppColor.danger
|
||||
accessibilityTraits = .button
|
||||
accessibilityHint = "移出常用应用"
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,11 +86,13 @@ final class AllFunctionMenuCell: UICollectionViewCell {
|
||||
titleLabel.textAlignment = .center
|
||||
titleLabel.numberOfLines = 2
|
||||
|
||||
actionButton.addTarget(self, action: #selector(actionTapped), for: .touchUpInside)
|
||||
isAccessibilityElement = true
|
||||
actionImageView.contentMode = .scaleAspectFit
|
||||
actionImageView.isUserInteractionEnabled = false
|
||||
|
||||
contentView.addSubview(cardView)
|
||||
cardView.addSubview(contentStackView)
|
||||
cardView.addSubview(actionButton)
|
||||
cardView.addSubview(actionImageView)
|
||||
contentStackView.addArrangedSubview(iconView)
|
||||
contentStackView.addArrangedSubview(titleLabel)
|
||||
|
||||
@ -96,13 +106,9 @@ final class AllFunctionMenuCell: UICollectionViewCell {
|
||||
iconView.snp.makeConstraints { make in
|
||||
make.width.height.equalTo(26)
|
||||
}
|
||||
actionButton.snp.makeConstraints { make in
|
||||
actionImageView.snp.makeConstraints { make in
|
||||
make.top.trailing.equalToSuperview().inset(AppSpacing.xxs)
|
||||
make.width.height.equalTo(20)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func actionTapped() {
|
||||
onActionTap?()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user