diff --git a/sample/Comet.Sample/Comparisons/Section5.cs b/sample/Comet.Sample/Comparisons/Section5.cs new file mode 100644 index 00000000..a85abd71 --- /dev/null +++ b/sample/Comet.Sample/Comparisons/Section5.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.Maui.Graphics; + +/* + // Flutter only support if render +class MyWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Column( + children: [ + if (someCondition == true) + Text('The condition is true!'), + ], + ); + } +} + +// Flutter render list +class MyWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Column( + children: [ + if (someCondition == true) ...[ + Text('Widget A'), + Text('Widget B'), + Text('Widget C'), + ], + ], + ); + } +} + + */ + +namespace Comet.Samples.Comparisons +{ + public class Section5 : View + { + bool showMore = true; + int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + string fillColor = "Red"; + [Body] + View body() => new VStack { + new Text("Hello Comet!"), + () => { + if(showMore) + return new Text("If condition is working"); + else + return new Text("Else condition is working"); + }, + nums.Select(i => new Text($"Show rows {i}")), + showMore?new Text("Ternary is working"):null, + () => { + switch(fillColor) + { + case "Red": + return new ShapeView(new Rectangle().Fill(Colors.Red)).Frame(100, 60); + default: + return null; + } + } + }; + + } +} diff --git a/sample/Comet.Sample/Views/MainPage.cs b/sample/Comet.Sample/Views/MainPage.cs index 3d98c383..f51c4e1b 100644 --- a/sample/Comet.Sample/Views/MainPage.cs +++ b/sample/Comet.Sample/Views/MainPage.cs @@ -73,6 +73,7 @@ namespace Comet.Samples new MenuItem("SwiftUI Tutorial Section 4b", ()=> new Section4b()), new MenuItem("SwiftUI Tutorial Section 4c", ()=> new Section4c()), new MenuItem("SwiftUI Tutorial Section 4d", ()=> new Section4c()), + new MenuItem("Compare with Flutter",() => new Section5()), new MenuItem("DavidSample1",()=> new DavidSample1()), new MenuItem("DavidSample1a",()=> new DavidSample1a()), new MenuItem("DavidSample1b",()=> new DavidSample1b()), diff --git a/src/Comet/Controls/ContainerView.cs b/src/Comet/Controls/ContainerView.cs index fc6e0b91..a02212e3 100644 --- a/src/Comet/Controls/ContainerView.cs +++ b/src/Comet/Controls/ContainerView.cs @@ -30,6 +30,12 @@ namespace Comet foreach (var v in ieiv) Add(v); } + else if (obj is Func func) + { + var view = func(); + if (view != null) + Add(view); + } else { throw new NotSupportedException("The object either needs to be a View, IView, or IEnumerable/IEnumerable");