Xamarin.SwiftUI icon indicating copy to clipboard operation
Xamarin.SwiftUI copied to clipboard

[C#] Make the source generator an optional optimization

Open chkn opened this issue 5 years ago • 1 comments

Currently, you can define the Body property on a custom view in a couple ways:

  1. Using the exact return type, e.g: public ModifiedBackground<Text,Color> Body => Text("hello").Background(Color.Red)

  2. 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)

chkn avatar Jun 06 '20 04:06 chkn

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.

chkn avatar Nov 30 '20 01:11 chkn