How can a View being re initialised in SwiftUI but the body not recomputed and the view re rendered?
Example
import SwiftUI
struct ContentView: View {
var body: some View {
SubView()
.padding()
}
}
struct SubView: View {
@State private var items = [Int]()
init() {
print("SubView init")
}
var body: some View {
Text("\(items.count)")
Button("Add item") { items.append(Int.random(in: 0..<10)) }
Divider()
SubSubView()
SubSubView()
}
}
struct SubSubView: View {
init() {
print("SubSubView init")
}
var body: some View {
Text("I'm a subview") (>> _breakpoint here_)
}
}
If I tap 4 times on the button, the view is the following:
But we have that in the console:
SubView init (>> app launch)
SubSubView init (>> app launch)
SubSubView init (>> app launch)
SubSubView init
SubSubView init
SubSubView init
SubSubView init
SubSubView init
SubSubView init
SubSubView init
SubSubView init
The SubSubView body
property is not recomputed (using a breakpoint).
Is this SubSubView re rendered only when there is any change in the view dependency, even if it's re initialized again?