Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/iOS/POI/POIAllTagsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions src/iOS/POI/POIAttributesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
28 changes: 12 additions & 16 deletions src/iOS/POI/POICommonTagsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/iOS/POI/POITabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading