-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Access ViewStore state dynamically via closure (#36)
* Access ViewStore state dynamically via closure This makes ViewStore's behavior more like that of Bindings. This is in reponse to an unusual bug we experienced while working on Subconscious. Was experiencing a mysterious crasher when factoring NavigationStack into a subview. What I discovered was that, at some point, NavigationStack seems to be attempting to mutate the array that manages that stack. I believe the fact that we pass the stack down as a value type may be causing the problem. It's obscured because the issue happens in Apple's proprietary SwiftUI code. The crash had to do with an array manipulation, and seemed likely to be related to the array that manages the view stack, or perhaps it with some sort of race condition in view rendering on the SwiftUI side. The workaround was giving NavigationStack a @State binding and replaying changes onto it. However, this made me wonder if the cause was the fact that we passed the stack by value down the the view, before creating a Binding that referenced it. After stubbing in a ViewStore with a Binding-like closure get function, the issue was resolved. So it seems that there are corner cases where SwiftUI needs to dynamically read the value via closure, not have it passed down by value. * Deprecated CursorProtocol and KeyedCursorProtocol Bring back these protocols for backwards-compat, but mark them deprecated.
- Loading branch information
1 parent
933547c
commit d16c8e0
Showing
2 changed files
with
184 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters