0

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()
    }
}
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. Commented Jul 23, 2022 at 18:18
  • Could you please give some advice on what container could be used instead? Commented Jul 24, 2022 at 8:43
  • 1
    Maybe you need something like this stackoverflow.com/a/62103264/12299030, or it can be helpful at least. Commented Jul 24, 2022 at 8:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.