Questions tagged [lazyvgrid]
131 questions
50
votes
1 answer
SwiftUI configure LazyVGrid with no spacing
I wanted to create a grid of cells with no spaces or smaller space just like the Photos app, is it possible with SwiftUI 2 LazyVGrid? I've tried it but there is always this space in-between columns.
In the documentation, the spacing parameter is…

randomor
- 5,329
- 4
- 46
- 68
15
votes
1 answer
How to use GeometryReader within a LazyVGrid
I'm building a grid with cards which have an image view at the top and some text at the bottom. Here is the swift UI code for the component:
struct Main: View {
var body: some View {
ScrollView {
LazyVGrid(columns:…

thexande
- 1,645
- 16
- 23
13
votes
1 answer
Using VStack with AsyncImage inside LazyVStack causes images to reload on scrolling
I'm trying to display a long list of images with titles using the new AsyncImage in SwiftUI. I noticed that when I put VStack around AsyncImage and scroll through images it's reloading images every time I scroll up or down. When there's no VStack I…

Maklaus
- 538
- 2
- 16
- 37
12
votes
1 answer
SwiftUI LazyVGrid - align top
I have a load of cards which I need to display in a vGrid. However, the cards have dynamic heights and what I want to do is have the cards in the columns align to the top.
This is the current setup:
let resultGridLayout =…

DevB1
- 1,235
- 3
- 17
- 43
11
votes
0 answers
LazyVGrid, List, LazyStacks don't release views from memory?
I'm playing around with the new photo picker in SwiftUI 2 and I made a simple app to show the imported images in a LazyVGrid but when scrolling down, if I imported around 150 images the app finish all the memory and it crashes (Terminated due to…

Ludyem
- 1,709
- 1
- 18
- 33
8
votes
1 answer
SwiftUI LazyVGrid dynamic row height
I would like to have a LazyVGrid of rows with same heights expanding/shrinking to fill the available parent height
Is it possible?
let columns = Array(repeating: GridItem(.flexible(minimum: 50, maximum: 100)), count: 3)
LazyVGrid(columns: columns,…

Simon Borkin
- 101
- 2
- 7
6
votes
1 answer
SwiftUI LazyVGrid lags with images
When I scroll my LazyVGrid, app lags a lot.
LazyVGrid(
columns: [
GridItem(.adaptive(minimum: horizontalSizeClass == .compact ? 160:320, maximum: 320), spacing: 16, alignment: .top)
],spacing: 16
){
ForEach(viewModel.articles){…

Dev
- 71
- 3
6
votes
0 answers
SwiftUI: Displaying variable length strings in a LazyVGrid
I'm trying to construct a vertical grid of strings that have variable lengths to be displayed side by side to each other (such as a collection of social media tags), as follows:
struct ContentView: View {
let data = ["first text",
"second…

JAHelia
- 6,934
- 17
- 74
- 134
6
votes
1 answer
How do I correctly pass a "cell item" to a .sheet from a SwiftUI LazyVGrid?
Here is my example, and I can't tell if this is a bug or not. All my cells load correctly, but when I try to bring up the DetailView() as a sheet, the item pased in is always whatevr item is shown first in the grid (in the top left in my case here),…

Rillieux
- 587
- 9
- 23
5
votes
1 answer
How to make SwiftUI Grid lay out evenly based on width?
I'm trying to use a SwiftUI Lazy Grid to lay out views with strings of varying lengths. How can I construct my code so that, e.g. if 3 view's do not fit, it will only make 2 columns and push the 3rd view to the next row so that they won't…

GarySabo
- 5,806
- 5
- 49
- 124
4
votes
2 answers
How to get a grid in SwiftUI with custom layout (different cell size)
So I am trying to get a custom grid with cells of different size. I have kinda gotten stuck here. So I have one particular cell with the height and size double that of all the others. But the left side of the cell requires two rows instead of one.…

Osama Naeem
- 1,830
- 5
- 16
- 34
4
votes
0 answers
SwiftUI: LazyVGrid not refreshing while scrolling
I have a LazyVGrid that displays search results, as I type characters in the search field, I perform CoreData fetch requests and update a @Published property.
Problem:
LazyVGrid updates results as expected EXCEPT if it is currently scrolling: in…

Kuringan
- 147
- 6
4
votes
0 answers
Is it possible to build a simple collection of flexible Views in SwiftUI using Grid?
What I'm trying to build is really very simple and common component. Here's the design:
Here's the code that I've tried till now:
struct ContentView: View {
var tags: [String]
var body: some View {
LazyVGrid(columns:…

Frankenstein
- 15,732
- 4
- 22
- 47
4
votes
1 answer
Add multiple LazyVGrid to ScrollView
I have an app that displays collections of thumbnails by days, each day is its own LazyVGrid and all days are bunched up in a VStack.
Bottom line, it looks like adding multiple LazyVGrid in a single ScrollView almost works... but doesn't.
It causes…

Yann Bizeul
- 403
- 3
- 10
4
votes
1 answer
How to make SwiftUI Text multilineTextAlignment start from Top and Center
How can I make the image and text alignment same as 3 other in SwiftUI LazyVGrid as I expected in image below?
I think the problem is how to make the text start from top if the text is multiline. In Android I can use gravity="top|center" but in…

doema
- 503
- 4
- 7