Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SwiftUI redraw #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix SwiftUI redraw #195

wants to merge 1 commit into from

Conversation

leoMehlig
Copy link
Contributor

I noticed that any view using a @Default property wrapper, was getting their body re-evaluated twice when appearing.

This is what the logs look like when showing a simple view that uses @Default when adding a Self._printChanges().

DefaultView: @self, @identity, @8 changed.
DefaultView: @8 changed.

The first line is totally normal, but the second line indicates that the value of @Default changed (no idea why SwiftUI is referring to it as @8).

I noticed that the Observable the property wrapper is using, will always send a objectWillChange after being initialized, even though it is already initialized with the correct value. Adding a initial parameter fixes this and will still update the property wrapper (and view) when the value actually changes.

After the change, only the first line gets logged.

Here is also the test project I used for this: Host.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant