InfoDisplaySettingsView.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // LoopFollow
  2. // InfoDisplaySettingsView.swift
  3. import SwiftUI
  4. struct InfoDisplaySettingsView: View {
  5. @ObservedObject var viewModel: InfoDisplaySettingsViewModel
  6. @State private var selectedID: Int?
  7. var body: some View {
  8. Form {
  9. Section(header: Text("General")) {
  10. Toggle(isOn: Binding(
  11. get: { Storage.shared.hideInfoTable.value },
  12. set: { Storage.shared.hideInfoTable.value = $0 }
  13. )) {
  14. Text("Hide Information Table")
  15. }
  16. }
  17. Section(
  18. header: Text("Information Display Settings"),
  19. footer: Text("Drag to reorder. Tap a row to set its visibility and colors.")
  20. ) {
  21. // The list stays in edit mode so rows are always draggable; a
  22. // Button (unlike NavigationLink) still receives taps in edit
  23. // mode, so reordering and navigation work at the same time.
  24. ForEach(viewModel.items) { item in
  25. Button {
  26. selectedID = item.id
  27. } label: {
  28. rowLabel(for: item)
  29. }
  30. .buttonStyle(.plain)
  31. }
  32. .onMove(perform: viewModel.move)
  33. }
  34. }
  35. .environment(\.editMode, .constant(.active))
  36. .navigationDestination(isPresented: Binding(
  37. get: { selectedID != nil },
  38. set: { if !$0 { selectedID = nil } }
  39. )) {
  40. if let id = selectedID {
  41. InfoRowSettingsView(item: viewModel.binding(for: id))
  42. }
  43. }
  44. .onDisappear {
  45. NotificationCenter.default.post(name: NSNotification.Name("refresh"), object: nil)
  46. }
  47. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  48. .navigationBarTitle("Information Display Settings", displayMode: .inline)
  49. }
  50. private func rowLabel(for item: InfoDisplayItem) -> some View {
  51. HStack {
  52. Text(item.type.name)
  53. Spacer()
  54. if item.type.isColorable, item.coloring.enabled {
  55. Circle()
  56. .fill(Color.orange)
  57. .frame(width: 8, height: 8)
  58. .accessibilityLabel("Coloring enabled")
  59. }
  60. Text(item.isVisible ? "On" : "Off")
  61. .foregroundStyle(.secondary)
  62. Image(systemName: "chevron.right")
  63. .font(.footnote.weight(.semibold))
  64. .foregroundStyle(.tertiary)
  65. }
  66. .contentShape(Rectangle())
  67. }
  68. }