I have some code that they must get fired after the View get completely rendered and drawn, as we know we got onAppear or onChange for a View, they can be useful to know wether the View has been appear or is under change, but they are not useful to be sure that the View has been 100% rendered, for example if we got ForEach, List or Form in the View, you could see the View but because of hierarchy could still ForEach working on View, so that means the View did not completely loaded, it could be get more noticeable if you gave an animation modifier then you could see it as well, So my goal is know how I can be 100% sure my View get rendered with everything inside and it would be no more line code to run for rendering the View?
thanks for reading and helping
Example:
import SwiftUI
struct ContentView: View {
var body: some View {
HierarchyView()
.onAppear() { print("HierarchyView"); print("- - - - - - - - - - -") }
}
}
struct HierarchyView: View {
var body: some View {
ZStack {
Color
.blue
.ignoresSafeArea()
.onAppear() { print("blue"); print("- - - - - - - - - - -") }
VStack {
Text("Top text")
.onAppear() { print("Top Text") }
Spacer()
.onAppear() { print("Top Spacer") }
}
.onAppear() { print("Top VStack"); print("- - - - - - - - - - -") }
VStack {
VStack {
VStack {
ForEach(0..<3, id:\..self) { index in
Text(index.description)
.onAppear() { print(index.description); if (index == 0) { print("Last of second ForEach!!!") } }
}
}
.onAppear() { print("Middle VStack Inside DEEP"); print("- - - - - - - - - - -") }
}
.onAppear() { print("Middle VStack Inside"); print("- - - - - - - - - - -") }
}
.onAppear() { print("Middle VStack Outside"); print("- - - - - - - - - - -") }
VStack {
Spacer()
.onAppear() { print("Bottom Spacer") }
ForEach(0..<3, id:\..self) { index in
Text(index.description)
.onAppear() { print(index.description); if (index == 0) { print("Last of first ForEach!!!") } }
}
Text("Bottom text")
.onAppear() { print("Bottom Text") }
}
.onAppear() { print("Bottom VStack"); print("- - - - - - - - - - -") }
}
.onAppear() { print("ZStack of HierarchyView"); print("- - - - - - - - - - -") }
}
}