SwiftUI load all views in TabView on appearance of the first tab

705 Views Asked by At

My TabView looks like this:

var body: some View {
    TabView {
        TabView1()
            .tabItem() {
                Image("...")
                Text("...")
            }
            .onAppear { ??? }

        TabView2()
            .tabItem() {
                Image("...")
                Text("...")
            }
    }
    .onAppear { ??? }
}

When I enter the TabView, I'll be on TabView1. What I want to do is to load the content inside TabView2 when I'm on TabView1, so that the content in TabView2 is prepared when I click and switch to it.

I'm guessing that I need to do something in any of the .onAppear methods, but what exactly should I do? Thanks a lot!

0

There are 0 best solutions below