Open swestwood opened 11 months ago
I also encountered it, how to solve it
Probably related to https://github.com/dkk/WrappingHStack/issues/15
A relatively easy workaround would be to pass the environmentObjects as parameters to you views
Example:
Instead of
WrappingHStack{
YourView()
}
.environment(someObject)
do:
WrappingHStack{
YourView(someObject)
}
Describe the bug When a view nested inside of WrappingHStack tries to access an environment object on its initial render, it cannot find it and throws a fatal error. (see example below)
If the nested view waits until after the first render to access the environment object, it works.
In either case for the code below, replacing WrappingHStack with HStack works properly.
To Reproduce Steps to reproduce the behavior:
Expected behavior Replacing
WrappingHStack
withHStack
gives the expected behavior of being able to access the environment object on initial render instead of crashing.Context:
Additional context Add any other context about the problem here.
Simplified Example (adapted from https://www.hackingwithswift.com/quick-start/swiftui/how-to-use-environmentobject-to-share-data-between-views)