2

I'm new in iOS. Now I'm trying to make some view looks like CSS's Flexbox.

struct FlexStack: View {

    let maxItemCountAtLine: Int
    let arr: [String]

    @State var idx:Int = 0

    var body: some View {
        VStack {
            ForEach(0 ..< (arr.count/maxItemCountAtLine)+1) { _ in
                HStack {
                    ForEach(0..<maxItemCountAtLine) { _ in
                        Text(arr[idx])
                        plusIdx()
                    }
                }
            }
        }
    }

    private func plusIdx() -> some View {
        self.idx += 1
        return EmptyView()
    }
}

I know the idx won't updated because this view is still drawing.

How can I make this work properly?

aheze
  • 24,434
  • 8
  • 68
  • 125
J.Dragon
  • 699
  • 8
  • 16

0 Answers0