Fix primary navigation editing

This commit is contained in:
Georg Bauer
2026-08-15 20:18:51 +02:00
parent 59bcddfadf
commit ac6de7d4f2
4 changed files with 36 additions and 27 deletions

View File

@@ -267,7 +267,7 @@ final class AppContext {
extension PrimaryDestination: CaseIterable {
public static var allCases: [PrimaryDestination] {
[.issues, .repositories, .pullRequests, .milestones, .actions, .serverActivity]
[.issues, .repositories, .pullRequests, .milestones, .actions]
}
var title: String {

View File

@@ -27,12 +27,12 @@ final class NavigationSettingsViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
section == 0 ? "Shown After Home" : "Available on Home"
section == 0 ? "Shown After Home" : "Available Destinations"
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
section == 0
? "Choose up to four destinations. Tap Edit to reorder them. Home is always first."
? "Tap Edit to add, remove, or reorder up to four destinations. Home is always first."
: "Destinations not in the tab bar remain available as buttons on Home."
}
@@ -49,19 +49,18 @@ final class NavigationSettingsViewController: UITableViewController {
if indexPath.section == 1 && selected.count == 4 {
content.textProperties.color = .secondaryLabel
content.imageProperties.tintColor = .tertiaryLabel
cell.selectionStyle = .none
} else if indexPath.section == 1 {
let add = UIImageView(image: UIImage(systemName: "plus.circle.fill"))
add.tintColor = .tintColor
cell.accessoryView = add
cell.accessibilityHint = "Adds this destination to the tab bar"
}
cell.selectionStyle = .none
cell.contentConfiguration = content
return cell
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
tableView.isEditing && (indexPath.section == 0 || selected.count < 4)
}
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
indexPath.section == 0
tableView.isEditing && indexPath.section == 0
}
override func tableView(
@@ -93,7 +92,8 @@ final class NavigationSettingsViewController: UITableViewController {
_ tableView: UITableView,
editingStyleForRowAt indexPath: IndexPath
) -> UITableViewCell.EditingStyle {
indexPath.section == 0 ? .delete : .none
if indexPath.section == 0 { return .delete }
return selected.count < 4 ? .insert : .none
}
override func tableView(
@@ -101,18 +101,20 @@ final class NavigationSettingsViewController: UITableViewController {
commit editingStyle: UITableViewCell.EditingStyle,
forRowAt indexPath: IndexPath
) {
guard editingStyle == .delete, indexPath.section == 0 else { return }
selected.remove(at: indexPath.row)
switch (editingStyle, indexPath.section) {
case (.delete, 0):
selected.remove(at: indexPath.row)
case (.insert, 1) where selected.count < 4:
selected.append(available[indexPath.row])
default:
return
}
save()
tableView.reloadData()
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard indexPath.section == 1, selected.count < 4 else { return }
selected.append(available[indexPath.row])
save()
tableView.reloadData()
}
private func save() {