Created
June 2, 2025 11:57
-
-
Save jacobsapps/e04666c4a55ff782e4161ea1ee07a5e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class CardCollectionViewModel: ObservableObject { | |
@Published var cards: [Card] = [] | |
func addCard(_ card: Card) { | |
cards.insert(card, at: 0) | |
} | |
} | |
struct CardGridView: View { | |
@StateObject private var viewModel = CardCollectionViewModel() | |
@State private var selectedCard: Card? = nil | |
@State private var showGeneration: Bool = false | |
var body: some View { | |
NavigationStack { | |
ScrollView { | |
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 3), spacing: 12) { | |
ForEach(viewModel.cards) { card in | |
CardView(card: card) | |
.onTapGesture { | |
selectedCard = card | |
} | |
} | |
} | |
.padding() | |
} | |
.sheet(isPresented: $showGeneration) { | |
GenerationView { newCard in | |
viewModel.addCard(newCard) | |
showGeneration = false | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment