I managed to work it around by adding viewDidAppear callback to SwiftUI, and replacing onAppear callbacks with it.
The code: https://gist.github.com/alongotv/7f450e8c47ed3f057e1f6d35443af269
Usage: apply onDidAppear modifier instead of onAppear to those views you use in TabView.
A rough example:
struct RootView: View {
@State var selection: Int = 1
var body: some View {
TabView(selection: $selection) {
FirstTabView().tag(1)
SecondTabView().tag(2)
}
}
}
struct FirstTabView: View {
var body: some View {
Text("first tab view")
.onDidAppear {
// load data
}
}
}
struct SecondTabView: View {
var body: some View {
Text("second tab view")
.onDidAppear {
// load data
}
}
}
Hope this helps.