From c60aa3e3f3c5725bfd437a61ca9c5da5b38a0359 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 1 Jun 2024 10:56:31 -0700 Subject: [PATCH] Fix close buttons unnecessarily being added to navigation column --- .../MultiColumnNavigationController.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Utilities/MultiColumnNavigationController.swift b/Tusker/Screens/Utilities/MultiColumnNavigationController.swift index 0f07f24b60..e1537c8de7 100644 --- a/Tusker/Screens/Utilities/MultiColumnNavigationController.swift +++ b/Tusker/Screens/Utilities/MultiColumnNavigationController.swift @@ -273,12 +273,17 @@ private class ColumnView: UIView { } private func installCloseBarButton(navigationItem: UINavigationItem) { - let item = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .done, target: self, action: #selector(closeNavigationColumn)) - item.accessibilityLabel = "Close Column" - if navigationItem.leftBarButtonItems != nil { - navigationItem.leftBarButtonItems!.insert(item, at: 0) + func makeItem() -> UIBarButtonItem { + let item = UIBarButtonItem(image: UIImage(systemName: "xmark"), style: .done, target: self, action: #selector(closeNavigationColumn)) + item.accessibilityLabel = "Close Column" + return item + } + if let leftItems = navigationItem.leftBarButtonItems { + if !leftItems.contains(where: { $0.action == #selector(closeNavigationColumn) }) { + navigationItem.leftBarButtonItems!.insert(makeItem(), at: 0) + } } else { - navigationItem.leftBarButtonItems = [item] + navigationItem.leftBarButtonItems = [makeItem()] } }