SwiftUI @ViewBuilder Result is a TupleView, How is Apple Using It And Able to Avoid Turning Things Into AnyVIew?

I was implementing FlexContainer (like flex layout in html&css).
I am on half of my way, and this is my code:

struct FlexContainer: View {
    
    let children: [AnyView]
    
    
    init<C1: View, C2: View>(@ViewBuilder content: () -> TupleView<(C1, C2)>) {
        self.children = [AnyView(content().value.0),
                         AnyView(content().value.1)]
    }
    
    init<C1: View, C2: View, C3: View>(@ViewBuilder content: () -> TupleView<(C1, C2, C3)>) {
        self.children = [AnyView(content().value.0),
                         AnyView(content().value.1),
                         AnyView(content().value.2)]
    }
    
    init<C1: View, C2: View, C3: View, C4: View>(@ViewBuilder content: () -> TupleView<(C1, C2, C3, C4)>) {
        self.children = [AnyView(content().value.0),
                         AnyView(content().value.1),
                         AnyView(content().value.2),
                         AnyView(content().value.3)]
    }
    
    
    
    var body: some View {
        GeometryReader { bounds in
            if self.children.count == 2 {
                self.children[0]
                    .position(x: 0, y: 0)
                self.children[1]
                    .position(x: 20, y: 0)
            }
            else if self.children.count == 3 {
                
            }
        }
    }
}

I think, the VStack, HStack, ZStack are implemented such a way. But I don't know how to get childs size, in order to layout all childs

1 Like