From b74adc3dd1f93646e42c1b92040975af08bfdc0f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 30 May 2026 15:43:32 +0000 Subject: [PATCH] Attributes tab: Done dismisses POI editor when tags unchanged When the tag dictionary matches the map object, Done now dismisses without calling commitChanges(). When tags changed, behavior is unchanged: dismiss then commit. Removed viewWillAppear logic that disabled Done when there were no edits. Fix Done dismiss when tags unchanged on Common/All Tags tabs Disabled UIBarButtonItem does not invoke done:, so gray checkmark could highlight without closing. Keep Done enabled and use tint for gray/blue; only commit when isTagDictChanged(). Shared updateSaveButton on POITabBarController. Co-Authored-By: Tobias --- src/iOS/POI/POIAllTagsViewController.swift | 27 ++++++++---------- src/iOS/POI/POIAttributesViewController.swift | 12 +++++--- src/iOS/POI/POICommonTagsViewController.swift | 28 ++++++++----------- src/iOS/POI/POITabBarController.swift | 15 ++++++++++ 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/iOS/POI/POIAllTagsViewController.swift b/src/iOS/POI/POIAllTagsViewController.swift index 5066327d7..78f29c1a4 100644 --- a/src/iOS/POI/POIAllTagsViewController.swift +++ b/src/iOS/POI/POIAllTagsViewController.swift @@ -171,10 +171,7 @@ class POIAllTagsViewController: UITableViewController, POIFeaturePickerDelegate, tags.setWithoutSorting(list) tableView.reloadData() - saveButton.isEnabled = tabController.isTagDictChanged() - if #available(iOS 13.0, *) { - tabBarController?.isModalInPresentation = saveButton.isEnabled - } + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: tabController.isTagDictChanged()) return nextRow } @@ -390,10 +387,9 @@ class POIAllTagsViewController: UITableViewController, POIFeaturePickerDelegate, kvCell.isSet.backgroundColor = kv.k == "" || kv.v == "" ? nil : UIColor.systemBlue let tabController = tabBarController as! POITabBarController - saveButton.isEnabled = tabController.isTagDictChanged(tags.keyValueDictionary()) - if #available(iOS 13.0, *) { - tabBarController?.isModalInPresentation = saveButton.isEnabled - } + tabController.updateSaveButton( + saveButton, + hasUnsavedTagChanges: tabController.isTagDictChanged(tags.keyValueDictionary())) } func keyValueEditingEnded(for kvCell: KeyValueTableCell) { @@ -525,10 +521,7 @@ class POIAllTagsViewController: UITableViewController, POIFeaturePickerDelegate, tableView.deleteRows(at: [indexPath], with: .fade) } - saveButton.isEnabled = tabController.isTagDictChanged() - if #available(iOS 13.0, *) { - tabBarController?.isModalInPresentation = saveButton.isEnabled - } + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: tabController.isTagDictChanged()) } else if editingStyle == .insert { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } @@ -540,11 +533,15 @@ class POIAllTagsViewController: UITableViewController, POIFeaturePickerDelegate, } @IBAction func done(_ sender: Any) { - dismiss(animated: true) saveState() + dismiss(animated: true) - let tabController = tabBarController as? POITabBarController - tabController?.commitChanges() + guard let tabController = tabBarController as? POITabBarController, + tabController.isTagDictChanged() + else { + return + } + tabController.commitChanges() } override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { diff --git a/src/iOS/POI/POIAttributesViewController.swift b/src/iOS/POI/POIAttributesViewController.swift index 5484462dc..650b5a993 100644 --- a/src/iOS/POI/POIAttributesViewController.swift +++ b/src/iOS/POI/POIAttributesViewController.swift @@ -45,8 +45,9 @@ class POIAttributesViewController: UITableViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - let tabController = tabBarController as? POITabBarController - saveButton.isEnabled = tabController?.isTagDictChanged() ?? false + if let tabController = tabBarController as? POITabBarController { + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: tabController.isTagDictChanged()) + } } override func numberOfSections(in tableView: UITableView) -> Int { @@ -294,8 +295,11 @@ class POIAttributesViewController: UITableViewController { @IBAction func done(_ sender: Any) { dismiss(animated: true) - if let tabController = tabBarController as? POITabBarController { - tabController.commitChanges() + guard let tabController = tabBarController as? POITabBarController, + tabController.isTagDictChanged() + else { + return } + tabController.commitChanges() } } diff --git a/src/iOS/POI/POICommonTagsViewController.swift b/src/iOS/POI/POICommonTagsViewController.swift index cd25d81d5..26575765b 100644 --- a/src/iOS/POI/POICommonTagsViewController.swift +++ b/src/iOS/POI/POICommonTagsViewController.swift @@ -135,10 +135,7 @@ class POICommonTagsViewController: UITableViewController, UITextFieldDelegate, U tabController.keyValueDict.removeValue(forKey: key) } - saveButton.isEnabled = tabController.isTagDictChanged() - if #available(iOS 13.0, *) { - tabController.isModalInPresentation = saveButton.isEnabled - } + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: tabController.isTagDictChanged()) } func updateTagDict(withValue value: String, forKey key: String) { @@ -153,10 +150,7 @@ class POICommonTagsViewController: UITableViewController, UITextFieldDelegate, U func updatePresets() { let tabController = tabBarController as! POITabBarController - saveButton.isEnabled = tabController.isTagDictChanged() - if #available(iOS 13.0, *) { - tabController.isModalInPresentation = saveButton.isEnabled - } + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: tabController.isTagDictChanged()) if drillDownGroup == nil { let dict = tabController.keyValueDict @@ -604,8 +598,12 @@ class POICommonTagsViewController: UITableViewController, UITextFieldDelegate, U resignAll() dismiss(animated: true) - let tabController = tabBarController as? POITabBarController - tabController?.commitChanges() + guard let tabController = tabBarController as? POITabBarController, + tabController.isTagDictChanged() + else { + return + } + tabController.commitChanges() } // MARK: - Table view delegate @@ -687,9 +685,8 @@ class POICommonTagsViewController: UITableViewController, UITextFieldDelegate, U } @IBAction func textFieldChanged(_ textField: UITextField) { - saveButton.isEnabled = true - if #available(iOS 13.0, *) { - tabBarController?.isModalInPresentation = saveButton.isEnabled + if let tabController = tabBarController as? POITabBarController { + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: true) } if let cell: UITableViewCell = textField.superviewOfType() { switch cell { @@ -748,9 +745,8 @@ class POICommonTagsViewController: UITableViewController, UITextFieldDelegate, U } func textViewDidChange(_ textView: UITextView) { - saveButton.isEnabled = true - if #available(iOS 13.0, *) { - tabBarController?.isModalInPresentation = saveButton.isEnabled + if let tabController = tabBarController as? POITabBarController { + tabController.updateSaveButton(saveButton, hasUnsavedTagChanges: true) } // This resizes the cell to be appropriate for the content diff --git a/src/iOS/POI/POITabBarController.swift b/src/iOS/POI/POITabBarController.swift index ca4c67ef3..2835f1447 100644 --- a/src/iOS/POI/POITabBarController.swift +++ b/src/iOS/POI/POITabBarController.swift @@ -123,6 +123,21 @@ class POITabBarController: UITabBarController { return isTagDictChanged(keyValueDict) } + /// Keeps Done tappable (so it can dismiss with no edits) while tint reflects unsaved tag changes. + func updateSaveButton(_ saveButton: UIBarButtonItem, hasUnsavedTagChanges: Bool) { + saveButton.isEnabled = true + if hasUnsavedTagChanges { + saveButton.tintColor = nil + } else if #available(iOS 13.0, *) { + saveButton.tintColor = .tertiaryLabel + } else { + saveButton.tintColor = .lightGray + } + if #available(iOS 13.0, *) { + isModalInPresentation = hasUnsavedTagChanges + } + } + override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { guard let tabIndex = tabBar.items?.firstIndex(of: item),