diff --git a/Mastodon/Diffiable/Section/ReportSection.swift b/Mastodon/Diffiable/Section/ReportSection.swift index 86a12a9a3..eccf09d26 100644 --- a/Mastodon/Diffiable/Section/ReportSection.swift +++ b/Mastodon/Diffiable/Section/ReportSection.swift @@ -48,7 +48,13 @@ extension ReportSection { ) } - cell.setupSelected(attribute.isSelected) + // defalut to select the report status + if attribute.isSelected { + tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none) + } else { + tableView.deselectRow(at: indexPath, animated: false) + } + return cell default: return nil diff --git a/Mastodon/Scene/Report/ReportViewController.swift b/Mastodon/Scene/Report/ReportViewController.swift index 0bdd72bc9..487efa124 100644 --- a/Mastodon/Scene/Report/ReportViewController.swift +++ b/Mastodon/Scene/Report/ReportViewController.swift @@ -68,6 +68,7 @@ class ReportViewController: UIViewController, NeedsDependency { tableView.backgroundColor = .clear tableView.translatesAutoresizingMaskIntoConstraints = false tableView.delegate = self + tableView.allowsMultipleSelection = true return tableView }() @@ -277,7 +278,13 @@ extension ReportViewController: UITableViewDelegate { guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { return } - + didToggleSelected.send(item) + } + + func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) { + guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else { + return + } didToggleSelected.send(item) } } diff --git a/Mastodon/Scene/Report/ReportViewModel.swift b/Mastodon/Scene/Report/ReportViewModel.swift index e1de26039..26c0f2f2a 100644 --- a/Mastodon/Scene/Report/ReportViewModel.swift +++ b/Mastodon/Scene/Report/ReportViewModel.swift @@ -113,7 +113,6 @@ class ReportViewModel: NSObject { input.didToggleSelected.sink { [weak self] (item) in guard let self = self else { return } guard case let .reportStatus(objectID, attribute) = item else { return } - guard var snapshot = self.diffableDataSource?.snapshot() else { return } let managedObjectContext = self.statusFetchedResultsController.fetchedResultsController.managedObjectContext guard let status = managedObjectContext.object(with: objectID) as? Status else { return @@ -126,9 +125,6 @@ class ReportViewModel: NSObject { self.reportQuery.remove(statusID: status.id) } - snapshot.reloadItems([item]) - self.diffableDataSource?.apply(snapshot, animatingDifferences: false) - let continueEnable = (self.reportQuery.statusIDs?.count ?? 0) > 0 self.continueEnableSubject.send(continueEnable) } diff --git a/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift b/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift index 8329124cc..0c63398d1 100644 --- a/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift +++ b/Mastodon/Scene/Report/ReportedStatusTableviewCell.swift @@ -20,7 +20,6 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell { var disposeBag = Set() var pollCountdownSubscription: AnyCancellable? var observations = Set() - var checked: Bool = false let statusView = StatusView() let separatorLine = UIView.separatorLine @@ -42,7 +41,6 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell { override func prepareForReuse() { super.prepareForReuse() - checked = false statusView.updateContentWarningDisplay(isHidden: true, animated: false) statusView.statusMosaicImageViewContainer.contentWarningOverlayView.isUserInteractionEnabled = true statusView.pollTableView.dataSource = nil @@ -75,11 +73,22 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell { if highlighted { checkbox.image = UIImage(systemName: "checkmark.circle.fill") checkbox.tintColor = Asset.Colors.Label.highlight.color - } else if !checked { + } else if !isSelected { checkbox.image = UIImage(systemName: "circle") checkbox.tintColor = Asset.Colors.Label.secondary.color } } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + if isSelected { + checkbox.image = UIImage(systemName: "checkmark.circle.fill") + } else { + checkbox.image = UIImage(systemName: "circle") + } + checkbox.tintColor = Asset.Colors.Label.secondary.color + } } extension ReportedStatusTableViewCell { @@ -127,16 +136,6 @@ extension ReportedStatusTableViewCell { resetSeparatorLineLayout() } - - func setupSelected(_ selected: Bool) { - checked = selected - if selected { - checkbox.image = UIImage(systemName: "checkmark.circle.fill") - } else { - checkbox.image = UIImage(systemName: "circle") - } - checkbox.tintColor = Asset.Colors.Label.secondary.color - } } extension ReportedStatusTableViewCell {