I have learnt that in iOS 13-16 every @State property change will cause body recomputation. But I have examples where this statement is not true.
Case 1 (Passing @State to a view modifier). property showSheet is being toggled constantly but no rerendering occurs.
Case 2 (Passing @State to nested view). property counter is constantly changing when ChildView model is opened but no rerendering on ParentView
enum Example {
struct ParentView: View {
@State private var showSheet = false
@State private var parentCounter = 0
@State var counter: Int = 1
var body: some View {
let _ = Self._printChanges()
VStack(spacing: 20) {
Button("Increment Parent Counter (\(parentCounter))") {
parentCounter += 1
}
.background(.debug)
Button("Open Sheet") {
showSheet = true
}
.background(.debug)
}
.background(.debug)
.sheet(isPresented: $showSheet) {
ChildView(counter: $counter)
}
}
}
Is there any uniform rule that can be used to always predict will changing @State cause rerender. Or any other example where changing @State in View that owns @State property wont cause rerendering?