Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Last active February 23, 2026 21:22
Show Gist options
  • Select an option

  • Save StewartLynch/4cd9ff27f8da90cde5ec3cc580cfc0c6 to your computer and use it in GitHub Desktop.

Select an option

Save StewartLynch/4cd9ff27f8da90cde5ec3cc580cfc0c6 to your computer and use it in GitHub Desktop.
OccasionsList view for Gift Registry app
//
//----------------------------------------------
// Original project: GiftRegistry
//
// Follow me on Mastodon: https://iosdev.space/@StewartLynch
// Follow me on Threads: https://www.threads.net/@stewartlynch
// Follow me on Bluesky: https://bsky.app/profile/stewartlynch.bsky.social
// Follow me on X: https://x.com/StewartLynch
// Follow me on LinkedIn: https://linkedin.com/in/StewartLynch
// Email: slynch@createchsol.com
// Subscribe on YouTube: https://youTube.com/@StewartLynch
// Buy me a ko-fi: https://ko-fi.com/StewartLynch
//----------------------------------------------
// Copyright © 2026 CreaTECH Solutions (Stewart Lynch). All rights reserved.
import SwiftUI
struct OccasionsList: View {
enum Action: String {
case new = "New Occasion"
case edit = "Edit Occasion"
case none = "Occasions"
}
@State private var action = Action.none
@State private var newOccasion = false
@State private var name = ""
@State private var hexColor = Color.blue
@Environment(\.dismiss) var dismiss
var body: some View {
NavigationStack {
VStack {
if action != .none {
HStack {
TextField("Occasion Name", text: $name)
.textFieldStyle(.roundedBorder)
ColorPicker("Color", selection: $hexColor, supportsOpacity: false)
.labelsHidden()
if !name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
Button {
// Create or update an occasions using an upsert
} label: {
Image(systemName: "checkmark")
}
.buttonStyle(.glassProminent)
}
}
}
// if list of occasions is empty, display contentUnavailableView
// else display list of occasions
List {
// Display list of occasions in rows
// Each row will display the name along with a button that will indicate whether or not the current gift already includes that occasion and tapping the button will either add or remove the occasion from the array passed in.
// Tapping on row will enable edits on the particular occasion
// A Swipe action on the row will delete the occasions
}
}
.padding()
.navigationTitle(action.rawValue)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(role: .cancel) {
dismiss()
}
}
ToolbarItem(placement: .confirmationAction) {
Button(role: .confirm) {
dismiss()
}
}
ToolbarItem(placement: .topBarTrailing) {
Button {
action = .new
} label: {
Image(systemName: "plus")
}
}
}
}
}
}
#Preview {
OccasionsList()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment