From 41db3e42ceea6695c87e869bff58e52d4ec77b6d Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 26 Oct 2022 17:25:21 -0500 Subject: [PATCH] Fixes Error Log context menu appearing while scrolling table view --- .../Error Log/ErrorLogViewController.swift | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/AltStore/Settings/Error Log/ErrorLogViewController.swift b/AltStore/Settings/Error Log/ErrorLogViewController.swift index ed7acf70..6e74499f 100644 --- a/AltStore/Settings/Error Log/ErrorLogViewController.swift +++ b/AltStore/Settings/Error Log/ErrorLogViewController.swift @@ -19,6 +19,13 @@ class ErrorLogViewController: UITableViewController private lazy var dataSource = self.makeDataSource() private var expandedErrorIDs = Set() + private var isScrolling = false { + didSet { + guard self.isScrolling != oldValue else { return } + self.updateButtonInteractivity() + } + } + private lazy var timeFormatter: DateFormatter = { let dateFormatter = DateFormatter() dateFormatter.dateStyle = .none @@ -106,6 +113,15 @@ private extension ErrorLogViewController ]) cell.menuButton.menu = menu + + if self.isScrolling + { + cell.menuButton.showsMenuAsPrimaryAction = false + } + else + { + cell.menuButton.showsMenuAsPrimaryAction = true + } } // Include errorDescriptionTextView's text in cell summary. @@ -315,3 +331,39 @@ extension ErrorLogViewController } } } + +extension ErrorLogViewController +{ + override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) + { + self.isScrolling = true + } + + override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) + { + self.isScrolling = false + } + + override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) + { + guard !decelerate else { return } + self.isScrolling = false + } + + private func updateButtonInteractivity() + { + guard #available(iOS 14, *) else { return } + + for case let cell as ErrorLogTableViewCell in self.tableView.visibleCells + { + if self.isScrolling + { + cell.menuButton.showsMenuAsPrimaryAction = false + } + else + { + cell.menuButton.showsMenuAsPrimaryAction = true + } + } + } +}