listless

A simple list app for Apple platforms
Log | Files | Refs | README | LICENSE

ItemListView+NavigationHeader.swift (2882B)


      1 import SwiftUI
      2 
      3 extension ItemListView {
      4     @ViewBuilder
      5     private var finishButton: some View {
      6         if #available(iOS 26.0, *) {
      7             Button {
      8                 onFinishTutorial?()
      9             } label: {
     10                 Text("Finish")
     11                     .font(.body)
     12                     .fontWeight(.semibold)
     13                     .padding(.horizontal, 12)
     14                     .padding(.vertical, 8)
     15                     .glassEffect(.clear)
     16             }
     17             .tint(.secondary)
     18         } else {
     19             Button("Finish") {
     20                 onFinishTutorial?()
     21             }
     22             .font(.body)
     23             .fontWeight(.semibold)
     24             .foregroundStyle(.secondary)
     25         }
     26     }
     27 
     28     @ViewBuilder
     29     private var overflowMenu: some View {
     30         if #available(iOS 26.0, *) {
     31             Menu {
     32                 overflowMenuItems
     33             } label: {
     34                 Image(systemName: "ellipsis")
     35                     .font(.title2)
     36                     .padding()
     37                     .glassEffect(.clear)
     38             }
     39             .tint(.secondary)
     40         } else {
     41             Menu {
     42                 overflowMenuItems
     43             } label: {
     44                 Image(systemName: "ellipsis.circle")
     45                     .font(.title2)
     46                     .foregroundStyle(.secondary)
     47                     .frame(width: 44, height: 44)
     48             }
     49             .buttonStyle(.plain)
     50         }
     51     }
     52 
     53     @ViewBuilder
     54     private var overflowMenuItems: some View {
     55         Button {
     56             showRenameAlert()
     57         } label: {
     58             Label("Rename List", systemImage: "pencil")
     59         }
     60         Button(role: .destructive) {
     61             iState.isShowingDeleteAllAlert = true
     62         } label: {
     63             Label("Delete All", systemImage: "trash")
     64         }
     65         .disabled(items.isEmpty)
     66         Divider()
     67         Button {
     68             showSettings()
     69         } label: {
     70             Label("Settings", systemImage: "gearshape")
     71         }
     72     }
     73 
     74     var navigationHeader: some View {
     75         HStack {
     76             Text(isTutorial ? "Tutorial" : listName)
     77                 .font(.largeTitle)
     78                 .fontWeight(.bold)
     79             Spacer()
     80             if isTutorial {
     81                 finishButton
     82             } else {
     83                 if syncMonitor.hasDiagnosticsIssue {
     84                     Button {
     85                         showSyncDiagnostics()
     86                     } label: {
     87                         Image(systemName: "exclamationmark.icloud")
     88                             .font(.title2)
     89                             .foregroundStyle(.red)
     90                     }
     91                 }
     92                 overflowMenu
     93             }
     94         }
     95         .padding(.horizontal, 16)
     96         .padding(.bottom, 8)
     97         .contentShape(Rectangle())
     98         .onTapGesture {
     99             fState.selectedItemID = nil
    100             focusedField = nil
    101         }
    102     }
    103 }