You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, you can define the Body property on a custom view in a couple ways:
Using the exact return type, e.g: public ModifiedBackground<Text,Color> Body => Text("hello").Background(Color.Red)
Using the View return type and the source generator: public View Body => Text("hello").Background(Color.Red)
The second form is clearly more readable and the first form can get out of hand quickly for even a trivial view hierarchy. However, the second form requires the source generator, and the source generator must be able to staticly determine the return type so it can emit the first form under the hood. When these requirements can't be satisfied, we should still enable the second form and expose this to Swift as AnyView
Bind AnyView
Modify CustomViewType to expose View-typed Body property as AnyView (see first comment)
The text was updated successfully, but these errors were encountered:
Modify CustomViewType to expose View-typed Body property as AnyView
On second thought, I think we should make it explicit and require people to declare the return type as AnyView. That way, it will be clear what's happening and force people to acknowledge the performance implications.
Currently, you can define the
Body
property on a custom view in a couple ways:Using the exact return type, e.g:
public ModifiedBackground<Text,Color> Body => Text("hello").Background(Color.Red)
Using the
View
return type and the source generator:public View Body => Text("hello").Background(Color.Red)
The second form is clearly more readable and the first form can get out of hand quickly for even a trivial view hierarchy. However, the second form requires the source generator, and the source generator must be able to staticly determine the return type so it can emit the first form under the hood. When these requirements can't be satisfied, we should still enable the second form and expose this to Swift as
AnyView
AnyView
Modify(see first comment)CustomViewType
to exposeView
-typed Body property asAnyView
The text was updated successfully, but these errors were encountered: