Skip to content

Commit

Permalink
Working on Balance sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
adospace committed Dec 11, 2024
1 parent f2dc660 commit f3ba038
Show file tree
Hide file tree
Showing 109 changed files with 2,236 additions and 1,188 deletions.
5 changes: 3 additions & 2 deletions src/MauiReactor.Scaffold/ComponentTypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public partial class Component

#line default
#line hidden
this.Write("(params VisualNode?[]? children)\r\n {\r\n var @");
this.Write("(params IEnumerable<VisualNode?>? children)\r\n {\r\n var @");

#line 32 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\ComponentTypeGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(type.Name.ToLower()));
Expand Down Expand Up @@ -213,7 +213,8 @@ public partial class Component

#line default
#line hidden
this.Write("?> componentRefAction, params VisualNode?[]? children)\r\n {\r\n var @");
this.Write("?> componentRefAction, params IEnumerable<VisualNode?>? children)\r\n {\r\n " +
" var @");

#line 51 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\ComponentTypeGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(type.Name.ToLower()));
Expand Down
4 changes: 2 additions & 2 deletions src/MauiReactor.Scaffold/ComponentTypeGenerator.tt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class Component
=> new <#= typeName #>();

<# if (typeof(Element).IsAssignableFrom(type)) { #>
public static <#= typeName #> <#= type.Name #>(params VisualNode?[]? children)
public static <#= typeName #> <#= type.Name #>(params IEnumerable<VisualNode?>? children)
{
var @<#= type.Name.ToLower() #> = new <#= typeName #>();
if (children != null)
Expand All @@ -46,7 +46,7 @@ public partial class Component
}

<# if (typeof(Element).IsAssignableFrom(type)) { #>
public static <#= typeName #> <#= type.Name #>(Action<<#= type.FullName #>?> componentRefAction, params VisualNode?[]? children)
public static <#= typeName #> <#= type.Name #>(Action<<#= type.FullName #>?> componentRefAction, params IEnumerable<VisualNode?>? children)
{
var @<#= type.Name.ToLower() #> = new <#= typeName #>();
@<#= type.Name.ToLower() #>.ComponentRefAction = componentRefAction;
Expand Down
2 changes: 1 addition & 1 deletion src/MauiReactor.Scaffold/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where typeof(BindableObject).IsAssignableFrom(assemblyType)
scaffoldedTypes.Add(typeToScaffold);
}

//GenerateComponentPartial(scaffoldedTypes, outputPath);
GenerateComponentPartial(scaffoldedTypes, outputPath);

Console.WriteLine("Done");

Expand Down
953 changes: 488 additions & 465 deletions src/MauiReactor.Scaffold/TypeGenerator.cs

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/MauiReactor.Scaffold/TypeGenerator.tt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ public partial class <#= TypeName() #> : <#= TypeName() #><<#= FullTypeName() #>
{

}

<# if (typeof(Element).IsAssignableFrom(_typeToScaffold)) { #>
public <#= TypeName() #>(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
<# } #>
}
<# } #>

Expand Down
14 changes: 14 additions & 0 deletions src/MauiReactor.ScaffoldGenerator/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,18 @@ public static bool IsNewModifierUsed(this IPropertySymbol propertySymbol)
// No matching property found in the base type or any ancestor type
return false;
}

public static bool IsDerivedFrom(this INamedTypeSymbol type, INamedTypeSymbol baseType)
{
INamedTypeSymbol? currentBaseType = type.BaseType;
while (currentBaseType != null)
{
if (currentBaseType.Equals(baseType, SymbolEqualityComparer.Default))
{
return true;
}
currentBaseType = currentBaseType.BaseType;
}
return false;
}
}
919 changes: 486 additions & 433 deletions src/MauiReactor.ScaffoldGenerator/ScaffoldTypeGenerator.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public ScaffoldTypeGenerator(
.First()
.Type
.GetFullyQualifiedName() : string.Empty;

var typeOfElement = compilation.FindNamedType("Microsoft.Maui.Controls.Element").EnsureNotNull();
IsTypeDerivingFromElement = typeToScaffold.IsDerivedFrom(typeOfElement);
}

private IPropertySymbol[] Properties { get; }
Expand Down Expand Up @@ -156,6 +159,7 @@ public ScaffoldTypeGenerator(
public INamedTypeSymbol TypeofColor { get; }

private string? BaseTypeNamespace { get; }

public bool IsBaseGenericType =>
TypeToScaffold.BaseType.EnsureNotNull().IsGenericType;

Expand Down Expand Up @@ -244,6 +248,8 @@ private bool IsTypeNotAbstractWithEmptyConstructor
private bool IsTypeSealed
=> TypeToScaffold.IsSealed;

private bool IsTypeDerivingFromElement { get; }

private string GetDelegateParametersDescriptor(IEventSymbol ev)
{
/*
Expand Down
20 changes: 20 additions & 0 deletions src/MauiReactor.ScaffoldGenerator/ScaffoldTypeGenerator.tt
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ namespace <#= Namespace #>
{

}

<# if (IsTypeDerivingFromElement) { #>
public <#= GeneratorType.Name #>(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
<# } #>
}
<# } #>

Expand All @@ -450,6 +460,16 @@ namespace <#= Namespace #>
{

}

<# if (IsTypeDerivingFromElement) { #>
public <#= GeneratorType.Name #>(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
<# } #>
}
<# } #>

Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/AbsoluteLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public AbsoluteLayout()
public AbsoluteLayout(Action<Microsoft.Maui.Controls.AbsoluteLayout?> componentRefAction) : base(componentRefAction)
{
}

public AbsoluteLayout(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class AbsoluteLayoutExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/ActivityIndicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public ActivityIndicator()
public ActivityIndicator(Action<Microsoft.Maui.Controls.ActivityIndicator?> componentRefAction) : base(componentRefAction)
{
}

public ActivityIndicator(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class ActivityIndicatorExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/BaseShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public BaseShellItem()
public BaseShellItem(Action<Microsoft.Maui.Controls.BaseShellItem?> componentRefAction) : base(componentRefAction)
{
}

public BaseShellItem(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class BaseShellItemExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public Border()
public Border(Action<Microsoft.Maui.Controls.Border?> componentRefAction) : base(componentRefAction)
{
}

public Border(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class BorderExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/BoxView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public BoxView()
public BoxView(Action<Microsoft.Maui.Controls.BoxView?> componentRefAction) : base(componentRefAction)
{
}

public BoxView(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class BoxViewExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ public Button()
public Button(Action<Microsoft.Maui.Controls.Button?> componentRefAction) : base(componentRefAction)
{
}

public Button(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class ButtonExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/CarouselView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public CarouselView()
public CarouselView(Action<Microsoft.Maui.Controls.CarouselView?> componentRefAction) : base(componentRefAction)
{
}

public CarouselView(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class CarouselViewExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public CheckBox()
public CheckBox(Action<Microsoft.Maui.Controls.CheckBox?> componentRefAction) : base(componentRefAction)
{
}

public CheckBox(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class CheckBoxExtensions
Expand Down
8 changes: 8 additions & 0 deletions src/MauiReactor/CollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public CollectionView()
public CollectionView(Action<Microsoft.Maui.Controls.CollectionView?> componentRefAction) : base(componentRefAction)
{
}

public CollectionView(params IEnumerable<VisualNode?>? children)
{
if (children != null)
{
this.AddChildren(children);
}
}
}

public static partial class CollectionViewExtensions
Expand Down
2 changes: 1 addition & 1 deletion src/MauiReactor/Compatibility/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,4 @@ public static partial class LayoutStyles
public static Dictionary<string, Action<ILayout>> Themes { get; } = [];
}

#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
14 changes: 10 additions & 4 deletions src/MauiReactor/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,26 @@ protected virtual void OnMountedOrPropsChanged()

}

public INavigation? Navigation
=> ContainerPage?.Navigation ?? NavigationProvider.Navigation;
public INavigation Navigation
=> ContainerPage?.Navigation ?? NavigationProvider.Navigation ?? throw new InvalidOperationException("Navigation not available");

public bool IsNavigationAvailable
=> ContainerPage?.Navigation != null || NavigationProvider.Navigation != null;

private Microsoft.Maui.Controls.Page? _containerPage;

public Microsoft.Maui.Controls.Page? ContainerPage
public Microsoft.Maui.Controls.Page ContainerPage
{
get
{
_containerPage ??= ((IVisualNode)this).GetContainerPage();
return _containerPage;
return _containerPage ?? throw new InvalidOperationException("ContainerPage not available");
}
}

public bool IsContainerPageAvailable
=> _containerPage != null || ((IVisualNode)this).GetContainerPage() != null;

public static IServiceProvider Services
=> ServiceCollectionProvider.ServiceProvider;

Expand Down
Loading

0 comments on commit f3ba038

Please sign in to comment.