In Reader
views such as GeometryReader
as well as ScrollViewReader
, the content area does not seem to detect changes in state correctly.
I googled the issue and found a few similar occurrences, but it wasn't clear to me why this was happening.
I think that a bug exist in some Reader
views's content rendering logic.
This is the code that reproduces the behavior.
Changes in state are correctly reflected in areas other than the GeometryReader
.
class ViewModel: ObservableObject {
@Published
var show: Bool = false
}
struct Parent: View {
let viewModel = ViewModel()
var body: some View {
Child(viewModel) {
VStack {
GeometryReader { _ in
// Not updated
Text(viewModel.show ? "A" : "B")
}
// Updated
Text(viewModel.show ? "AA" : "BB")
Button("toggle") {
viewModel.show.toggle()
}
}
}
}
}
struct Child<Content: View>: View {
var body: some View {
content()
}
@StateObject
var viewModel: ViewModel
let content: () -> Content
init(_ viewModel: ViewModel, content: @escaping () -> Content) {
self._viewModel = .init(wrappedValue: viewModel)
self.content = content
}
}
Do you have any information on this issue?