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

Some primitive Views cannot access @Environment #139

Closed
carson-katri opened this issue Jul 1, 2020 · 3 comments · Fixed by #146
Closed

Some primitive Views cannot access @Environment #139

carson-katri opened this issue Jul 1, 2020 · 3 comments · Fixed by #146
Labels
bug Something isn't working

Comments

@carson-katri
Copy link
Member

carson-katri commented Jul 1, 2020

For instance, the Text element inside of EnvironmentDemo will never get any Environment injected. You can see this by putting the following print after // Inject @Environment values in StackReconciler.swift:

print(compositeView.view.type)

The Text element is never logged.

I'm not sure how to fix this. Do you have any ideas @MaxDesiatov ?

@MaxDesiatov MaxDesiatov added the bug Something isn't working label Jul 1, 2020
@MaxDesiatov
Copy link
Collaborator

Thanks, I'll have a look...

@MaxDesiatov
Copy link
Collaborator

MaxDesiatov commented Jul 1, 2020

The reason for it is that Text (and possibly other views) doesn't conform to ViewDeferredToRenderer. That means it's rendered as a "host" view directly. The distinction between "host" (truly primitive) and "composite" (that have meaningful body) views is made in the reconciler in TokamakCore based on their body type, host views have body type Never. ViewDeferredToRenderer allows renderers to override that per-platform and render host views as composite by providing their deferredBody implementation. The @Environment handling you've added is only applied to composite views as it's added in the same place where @State is handled. The latter is only available to truly composite views. Most probably the environment injection shouldn't happen there, but somewhere else.

@carson-katri
Copy link
Member Author

Hmm, ok I'll try and find a better spot for it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants