Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct PhotoGridView: View {
- @State private var recipes: [Recipe] = []
- let columns = [
- GridItem(.flexible()),
- GridItem(.flexible())
- ]
- @State private var selectedRecipe: Recipe?
- var body: some View {
- NavigationView {
- ScrollView {
- LazyVGrid(columns: columns, spacing: 20) {
- ForEach(recipes) { recipe in
- RecipeGridItem(recipe: recipe)
- .onTapGesture {
- selectedRecipe = recipe
- }
- }
- }
- .padding()
- }
- .navigationTitle("Przepisy")
- .sheet(item: $selectedRecipe) { recipe in
- RecipeDetailView(recipe: recipe)
- }
- .onAppear(perform: loadRecipes)
- }
- }
- private func loadRecipes() {
- // Załaduj przepisy z pliku JSON
- if let url = Bundle.main.url(forResource: "recipes", withExtension: "json"),
- let data = try? Data(contentsOf: url),
- let loadedRecipes = try? JSONDecoder().decode([Recipe].self, from: data) {
- self.recipes = loadedRecipes
- }
- }
- }
- struct PhotoGridView_Previews: PreviewProvider {
- static var previews: some View {
- PhotoGridView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement