From da31598fd84c33d052c13181425411e2dc975594 Mon Sep 17 00:00:00 2001 From: Carlos Santos Date: Wed, 2 Sep 2020 18:50:35 +0100 Subject: [PATCH] Allow text selection on FNMDebugListingViewController via iOS 11 `UIContextualAction` and `UIActivityViewController` Also, SF Symbols relying on iOS 13 --- FNMNetworkMonitor.podspec | 2 +- .../FNMDebugListingViewController.swift | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/FNMNetworkMonitor.podspec b/FNMNetworkMonitor.podspec index ccc796e..aab28da 100755 --- a/FNMNetworkMonitor.podspec +++ b/FNMNetworkMonitor.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |spec| spec.name = 'FNMNetworkMonitor' spec.module_name = 'FNMNetworkMonitor' - spec.version = '9.0.0' + spec.version = '9.1.0' spec.summary = 'A network monitor' spec.homepage = 'https://github.com/Farfetch/network-monitor-ios' spec.license = 'MIT' diff --git a/NetworkMonitor/Classes/Debug/Controller/FNMDebugListingViewController.swift b/NetworkMonitor/Classes/Debug/Controller/FNMDebugListingViewController.swift index 9f97a9d..9770158 100644 --- a/NetworkMonitor/Classes/Debug/Controller/FNMDebugListingViewController.swift +++ b/NetworkMonitor/Classes/Debug/Controller/FNMDebugListingViewController.swift @@ -40,6 +40,7 @@ final class FNMDebugListingViewController: FNMViewController { type(of: self).defaults().set(newSortOrder.rawValue, forKey: SortOrder.key) } } + private var errorFilterType: ErrorFilterType = .allRequests // MARK: Lifecycle @@ -405,6 +406,41 @@ private extension FNMDebugListingViewController { } } +// MARK: - Private + +private extension FNMDebugListingViewController { + + @available(iOS 11.0, *) + func makeShareContextualAction(forRowAt indexPath: IndexPath) -> UIContextualAction { + + let action = UIContextualAction(style: .normal, title: nil) { [weak self] (action, swipeButtonView, completion) in + + guard let self = self else { + + return completion(false) + } + + if self.filteredRecords.count > indexPath.row, + let requestURL = self.filteredRecords[indexPath.row].request.url { + + let ac = UIActivityViewController(activityItems: [requestURL], applicationActivities: nil) + self.present(ac, animated: true) + } + + completion(true) + } + + action.backgroundColor = .systemTeal + + if #available(iOS 13, *) { + + action.image = UIImage(systemName: Constants.exportImage, withConfiguration: nil) + } + + return action + } +} + // MARK: - FNMNetworkMonitorObserver extension FNMDebugListingViewController: FNMNetworkMonitorObserver { @@ -467,6 +503,14 @@ extension FNMDebugListingViewController: UITableViewDelegate { animated: true) } } + + @available(iOS 11.0, *) + func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + + return UISwipeActionsConfiguration(actions: [ + self.makeShareContextualAction(forRowAt: indexPath) + ]) + } } // MARK: - UISearchBarDelegate