chkn / Xamarin.SwiftUI

.NET bindings for SwiftUI
MIT License
98 stars 7 forks source link

[C#] Make the source generator an optional optimization #22

Open chkn opened 4 years ago

chkn commented 4 years ago

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

chkn commented 3 years ago

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.