0

I want to create my own simplified implementation of VStack in SwiftUI without using any default containers. I understand that I need to use @ViewBuilder to pass views through a closures. But I cant understand how to get access to passed views to somehow iterate over them to calculate and set position of each passed view.

struct MyVStack<Content: View>: View {
    var content: () -> Content

    init(@ViewBuilder content: @escaping () -> Content) {
       self.content = content
    }

    var body: some View {
        viewsCollection = GetCollectionFrom(content()) // ???
        ForEach(viewsCollection) { view in
           // Calculate and set new positions of each view
           ....
        }
    }
}

I feel what I'm thinking in a right direction but doing something wrong.

Braiam
  • 1
  • 11
  • 47
  • 78

0 Answers0