Questions tagged [lazyvgrid]

131 questions
1
vote
2 answers

Swift UI - LazyVGrid and ForEach - cannot use duplicate items

New to SwiftUI and trying to display these emojis on separate CardViews inside of a LazyVGrid. When I use a ForEach loop to set one emoji per CardView, I cannot use duplicate emojis - even though I used id: \.self (actually, not entirely sure that…
1
vote
1 answer

Not able to run Grid views in swift ui

Xcode Version - 12.5 Swift Version - 5.4 code (ContentView.swift) When I try to run this code I get and error in SceneDelegate.swift as follows
1
vote
1 answer

matchedGeometryEffect on ScrollView memory leaks

Im using a LazyVGrid to show an article gallery. Everything is working fine, and I have no memory warnings, because every time a view leaves screen, memory usage is reduced. My problem is when I use matchedGeometryEffect with the image, in order to…
Dev
  • 71
  • 3
1
vote
2 answers

How to allow ForEach layout item to show duplicate item from array in SwiftUI?

I am working with on multiple choose answer quiz app. var itemsTemp = ["ant","bat", "bear", "bee", "bird", "butterfly", "camel", "cat", "cheetah","chick", "chicken"] Updated Here is example of my quiz app. let answerIndex = Int.random(in: 0...3)…
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73
1
vote
1 answer

How to create a 2 column grid with square shaped cells in SwiftUI

I'm trying to replicate this UI in SwiftUI using a Grid. I created the cell like this. struct MenuButton: View { let title: String let icon: Image var body: some View { Button(action: { print(#function) …
Isuru
  • 30,617
  • 60
  • 187
  • 303
1
vote
1 answer

Dynamically add cells to SwiftUI LazyGrid

How to dynamically add cells (not columns) to some LazyVGrid in SwiftUI? The following code should add 1 cell by clicking the button. It compiles but doesn't work. What I a missing? import SwiftUI struct GridContent: Identifiable { var id =…
1
vote
0 answers

LazyVGrid Items Overlap

I need some help with understanding why there is overlap in landscape with my Swift LazyVGrid. This is mentioned as an issue in this article: https://swiftui-lab.com/impossible-grids/ but I haven't found a great work around in my code. Here is the…
jlarks32
  • 931
  • 8
  • 20
1
vote
1 answer

How to drag across Views in a LazyVGrid with GeometryReader?

I want to drag across rectangles in a grid and change their color. This code is almost working, but this is not always the right rectangle that reacts: it behaves rather randomly. Any hints? import SwiftUI struct ContentView: View { let data =…
1
vote
1 answer

SwiftUI - contextMenu on LazyVGrid cell causing animation crash when Map present

I have a LazyVGrid and a NavigationBarItem button that changes the number of columns. It cycles through 1, 2, 3 then back to 1, etc. I use the .animation(.default) modifier to animate this change. When there is just one column I use a different cell…
Magnas
  • 3,832
  • 5
  • 33
  • 48
0
votes
0 answers

NavigationLink breaks LazyVGrid and View

I have come across a very unfortunate problem. I have constructed a view in SwiftUI and it is working perfectly, however only if it is the root view. Navigating to it via NavigationLink leads to a weird problem where only the elements that are…
Herbert
  • 21
  • 5
0
votes
0 answers

SwiftUI: Create zig-zag Grid

I'm trying to achieve the below effect on my LazyVGrid. Here's my current implementation. I would also like the Grid to span the available area. I tried setting .frame using GeometryReader but couldn't get to work. struct BSSoundComposerGridView:…
Ace Green
  • 381
  • 5
  • 29
0
votes
0 answers

NavigationLink destination view does not show when item clicked

In SwiftUI, I have a NavigationLink destination view that has if-else inside to return different body. Like this: var body: some View { NavigationLink(destination: { LocalAssetView(asset: asset) }) { …
user1783732
  • 1,599
  • 5
  • 22
  • 44
0
votes
1 answer

Display a LazyVGrid with Sections

I am trying to render a list of entities that are split into sections (think CoreData NSFetchedResultsSectionInfo). I believe this solution (or very similar) used to be in the documentation. I have tried several ways of doing this, either I get the…
Jeremy Quinn
  • 51
  • 1
  • 3
0
votes
1 answer

LazyVGrid with Text() affects spacing when content is empty

Total newbie, in Swift and SwiftUI but I couldn't find a straightforward answer hence, asking here. I have a LazyVGrid that contains a ForEach that renders RoundedRectangle that contains Text. The grid wraps the rectangles correctly and adds the…
skay-
  • 1,546
  • 3
  • 16
  • 26
0
votes
1 answer

iOS: inconsistent positioning when using LazyVGrid as a row in Form

I have code, where a LazyVGrid inside a Form is not rendered correctly the first time. After some scrolling, it renders correctly. this is iOS 16. My problem can be reproduced with this code. Should you try it, please use an iPhone(emulator) to…
Gerd Castan
  • 6,275
  • 3
  • 44
  • 89
1 2 3
8 9