1

Pretty newbe question I guess.

Target: A Grid that fills as much horizontal space as possible, that grows vertically.

My approach is using a LazyVGrid with a single GridItem(.adaptive(minimum: 40)).

However, for some reason all LazyVGrid children are given the width of 40, no more, that's why the following bug occurs.

Picture 1

enter image description here

Picture 2

enter image description here

Obviously, I want my the "1123" be represented as one line and be wider than the rest of the numbers, however for the reason I don't understand, in is divided into chunks and is shown as three lines.

Here's my code:

import SwiftUI



struct  NumbersViewTest: View {
    var  numbersAndOperators: [String] {
        ["+", "-", "*", "/", "1123", "2", "3", "4", "5", "6", "7", "8", "9", "0"] 
    }

    var gridItems: [GridItem] {
        [GridItem(.adaptive(minimum: 40, maximum: .infinity))]
    }



var body: some View {
    LazyVGrid(columns: gridItems) {
        ForEach(numbersAndOperators, id: \.self) { text in
            ZStack {
                Rectangle().stroke()
                    Text(text)
                        .font(.largeTitle)
                }
            }
        }
        .padding()
    }
}



struct  NumbersViewTest_Previews: PreviewProvider {
    static  var  previews: some  View {
        NumbersViewTest()
    }
}
boring_ape
  • 59
  • 3
  • 2
    It is grid, it is about columns, adaptive means "I'll calculate for you how many columns should be used", but columns always there. It can't support irregular layout (like tag cloud), so you need to select some other container and make custom layout. – Asperi Jul 23 '22 at 18:18
  • Could you please give some advice on what container could be used instead? – boring_ape Jul 24 '22 at 08:43
  • 1
    Maybe you need something like this https://stackoverflow.com/a/62103264/12299030, or it can be helpful at least. – Asperi Jul 24 '22 at 08:45

0 Answers0