I am trying to add buttons to a dynamic view. What I am trying to achieve us that I have an array and I want to create a list of buttons and want to fill that list horizontally first and when there is no space in screen next button should appear in next line and so on. I am proving an image for more understanding.Something like this image
I don't want to create a for list of loop for x number or text fields in Hstack. I am trying to achieve a dynamic width of button, one row may have 2 number of buttons and another may have 4 (according to length of text)
I already tried following code
var body: some View {
GeometryReader { geometry in
VStack {
ForEach(1...3) {_ in
HStack {
Color.orange.frame(width: 100, height: 100)
Color.orange.frame(width: 100, height: 100)
Color.orange.frame(width: 100, height: 100)
}.frame(width: geometry.size.width, height: 100)
}
}
}}
I already checked few answers but I am unable to find proper answer. If there is any proper answer there please provide a link before marking this question as duplicate.