Skip to content

Commit

Permalink
Fixing bugs with the new pattern + Inline component simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
adospace committed Jan 6, 2024
1 parent ffeef86 commit 74ad1b6
Show file tree
Hide file tree
Showing 57 changed files with 376 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
Solution_Name: ./src/MauiReactor.Build.sln
TemplatePack_Name: ./src/MauiReactor.TemplatePack/MauiReactor.TemplatePack.csproj
Version: 2.0.14-beta
Version: 2.0.15-beta

steps:
- name: Checkout
Expand Down
3 changes: 1 addition & 2 deletions samples/MauiReactor.TestApp/Pages/InlineComponentsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ static class Buttons
{
public static VisualNode IncrementButton()
{
return Component.Render(context =>
return Component.Render<int>(state =>
{
var state = context.UseState<int>();
return new Button(
state.Value == 0 ? "Click me!" : $"Counter is {state.Value}",
() => state.Set(s => ++s));
Expand Down
45 changes: 44 additions & 1 deletion src/MauiReactor.Scaffold/TypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public virtual string TransformText()
" ");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
if (Properties.Length > 0) {
if (Properties.Length > 0 || Events.Length > 0) {

#line default
#line hidden
Expand Down Expand Up @@ -554,6 +554,49 @@ public virtual string TransformText()
#line hidden
this.Write("\n ");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
foreach (var ev in Events) {
var genericArgs = ev.EventHandlerType.GetGenericArguments();

#line default
#line hidden
this.Write("\n thisAs");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName()));

#line default
#line hidden
this.Write(".");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ev.Name));

#line default
#line hidden
this.Write("Action = null;\n thisAs");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(InterfaceName()));

#line default
#line hidden
this.Write(".");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ev.Name));

#line default
#line hidden
this.Write("ActionWithArgs = null;\n ");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
}

#line default
#line hidden
this.Write("\n\n ");

#line 1 "C:\Source\github\reactorui-maui\src\MauiReactor.Scaffold\TypeGenerator.tt"
}

Expand Down
8 changes: 7 additions & 1 deletion src/MauiReactor.Scaffold/TypeGenerator.tt
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ public abstract partial class <#= TypeName() #><T> : <#= BaseTypeName() #><T>, <
{
base.Reset();

<# if (Properties.Length > 0) { #>
<# if (Properties.Length > 0 || Events.Length > 0) { #>
var thisAs<#= InterfaceName() #> = (<#= InterfaceName() #>)this;
<# foreach (var property in Properties) { #>
thisAs<#= InterfaceName() #>.<#= property.Name #> = null;
<# } #>
<# foreach (var ev in Events) {
var genericArgs = ev.EventHandlerType.GetGenericArguments(); #>
thisAs<#= InterfaceName() #>.<#= ev.Name #>Action = null;
thisAs<#= InterfaceName() #>.<#= ev.Name #>ActionWithArgs = null;
<# } #>

<# } #>

OnReset();
Expand Down
4 changes: 4 additions & 0 deletions src/MauiReactor/BaseShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ internal override void Reset()
thisAsIBaseShellItem.IsEnabled = null;
thisAsIBaseShellItem.Title = null;
thisAsIBaseShellItem.IsVisible = null;
thisAsIBaseShellItem.AppearingAction = null;
thisAsIBaseShellItem.AppearingActionWithArgs = null;
thisAsIBaseShellItem.DisappearingAction = null;
thisAsIBaseShellItem.DisappearingActionWithArgs = null;
OnReset();
}

Expand Down
6 changes: 6 additions & 0 deletions src/MauiReactor/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ internal override void Reset()
thisAsIButton.ImageSource = null;
thisAsIButton.Padding = null;
thisAsIButton.LineBreakMode = null;
thisAsIButton.ClickedAction = null;
thisAsIButton.ClickedActionWithArgs = null;
thisAsIButton.PressedAction = null;
thisAsIButton.PressedActionWithArgs = null;
thisAsIButton.ReleasedAction = null;
thisAsIButton.ReleasedActionWithArgs = null;
OnReset();
}

Expand Down
4 changes: 4 additions & 0 deletions src/MauiReactor/CarouselView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ internal override void Reset()
thisAsICarouselView.IsScrollAnimated = null;
thisAsICarouselView.CurrentItem = null;
thisAsICarouselView.Position = null;
thisAsICarouselView.CurrentItemChangedAction = null;
thisAsICarouselView.CurrentItemChangedActionWithArgs = null;
thisAsICarouselView.PositionChangedAction = null;
thisAsICarouselView.PositionChangedActionWithArgs = null;
OnReset();
}

Expand Down
6 changes: 6 additions & 0 deletions src/MauiReactor/Cell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ internal override void Reset()
base.Reset();
var thisAsICell = (ICell)this;
thisAsICell.IsEnabled = null;
thisAsICell.AppearingAction = null;
thisAsICell.AppearingActionWithArgs = null;
thisAsICell.DisappearingAction = null;
thisAsICell.DisappearingActionWithArgs = null;
thisAsICell.TappedAction = null;
thisAsICell.TappedActionWithArgs = null;
OnReset();
}

Expand Down
2 changes: 2 additions & 0 deletions src/MauiReactor/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ internal override void Reset()
var thisAsICheckBox = (ICheckBox)this;
thisAsICheckBox.IsChecked = null;
thisAsICheckBox.Color = null;
thisAsICheckBox.CheckedChangedAction = null;
thisAsICheckBox.CheckedChangedActionWithArgs = null;
OnReset();
}

Expand Down
2 changes: 2 additions & 0 deletions src/MauiReactor/Compatibility/Layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal override void Reset()
thisAsILayout.IsClippedToBounds = null;
thisAsILayout.CascadeInputTransparent = null;
thisAsILayout.Padding = null;
thisAsILayout.LayoutChangedAction = null;
thisAsILayout.LayoutChangedActionWithArgs = null;
OnReset();
}

Expand Down
18 changes: 14 additions & 4 deletions src/MauiReactor/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,21 @@ public static IServiceProvider Services
{
var parameterContext = new ParameterContext(this);
return parameterContext.Get<T>(name) ?? throw new InvalidOperationException($"Unable to find parameter with name '{name ?? typeof(T).FullName}'");
}

public static VisualNode Render(Func<ComponentContext, VisualNode> renderFunc)
}
protected IParameter<T> GetOrCreateParameter<T>(string? name = null) where T : new()
{
var parameterContext = new ParameterContext(this);
return parameterContext.Get<T>(name) ?? parameterContext.Create<T>(name);
}

//public static VisualNode Render(Func<ComponentContext, VisualNode> renderFunc)
//{
// return new InlineComponent(renderFunc);
//}

public static VisualNode Render<S>(Func<ComponentContextState<S>, VisualNode> renderFunc, S? defaultValue = default)
{
return new InlineComponent(renderFunc);
return new InlineComponent<S>(renderFunc, defaultValue);
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/MauiReactor/ContentPage.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,16 @@ public static ContentPage ContentPage(string title)
=> GetNodeFromPool<ContentPage>().Title(title);

public static ContentPage ContentPage(string title, params VisualNode?[]? children)
=> ContentPage(children).Title(title);
=> ContentPage(children).Title(title);
}

public static partial class ContentPageExtensions
{
public static T HasNavigationBar<T>(this T contentPage, bool hasNavigationBar)
where T : IContentPage, IVisualNodeWithAttachedProperties
{
contentPage.Set(Microsoft.Maui.Controls.NavigationPage.HasNavigationBarProperty, hasNavigationBar);
return contentPage;
}

}
2 changes: 2 additions & 0 deletions src/MauiReactor/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ internal override void Reset()
thisAsIDatePicker.FontSize = null;
thisAsIDatePicker.FontAttributes = null;
thisAsIDatePicker.FontAutoScalingEnabled = null;
thisAsIDatePicker.DateSelectedAction = null;
thisAsIDatePicker.DateSelectedActionWithArgs = null;
OnReset();
}

Expand Down
4 changes: 4 additions & 0 deletions src/MauiReactor/DragGestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ internal override void Reset()
base.Reset();
var thisAsIDragGestureRecognizer = (IDragGestureRecognizer)this;
thisAsIDragGestureRecognizer.CanDrag = null;
thisAsIDragGestureRecognizer.DropCompletedAction = null;
thisAsIDragGestureRecognizer.DropCompletedActionWithArgs = null;
thisAsIDragGestureRecognizer.DragStartingAction = null;
thisAsIDragGestureRecognizer.DragStartingActionWithArgs = null;
OnReset();
}

Expand Down
6 changes: 6 additions & 0 deletions src/MauiReactor/DropGestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ internal override void Reset()
base.Reset();
var thisAsIDropGestureRecognizer = (IDropGestureRecognizer)this;
thisAsIDropGestureRecognizer.AllowDrop = null;
thisAsIDropGestureRecognizer.DragLeaveAction = null;
thisAsIDropGestureRecognizer.DragLeaveActionWithArgs = null;
thisAsIDropGestureRecognizer.DragOverAction = null;
thisAsIDropGestureRecognizer.DragOverActionWithArgs = null;
thisAsIDropGestureRecognizer.DropAction = null;
thisAsIDropGestureRecognizer.DropActionWithArgs = null;
OnReset();
}

Expand Down
2 changes: 2 additions & 0 deletions src/MauiReactor/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal override void Reset()
thisAsIEditor.AutoSize = null;
thisAsIEditor.HorizontalTextAlignment = null;
thisAsIEditor.VerticalTextAlignment = null;
thisAsIEditor.CompletedAction = null;
thisAsIEditor.CompletedActionWithArgs = null;
OnReset();
}

Expand Down
16 changes: 16 additions & 0 deletions src/MauiReactor/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ internal override void Reset()
var thisAsIElement = (IElement)this;
thisAsIElement.AutomationId = null;
thisAsIElement.ClassId = null;
thisAsIElement.ChildAddedAction = null;
thisAsIElement.ChildAddedActionWithArgs = null;
thisAsIElement.ChildRemovedAction = null;
thisAsIElement.ChildRemovedActionWithArgs = null;
thisAsIElement.DescendantAddedAction = null;
thisAsIElement.DescendantAddedActionWithArgs = null;
thisAsIElement.DescendantRemovedAction = null;
thisAsIElement.DescendantRemovedActionWithArgs = null;
thisAsIElement.ParentChangingAction = null;
thisAsIElement.ParentChangingActionWithArgs = null;
thisAsIElement.ParentChangedAction = null;
thisAsIElement.ParentChangedActionWithArgs = null;
thisAsIElement.HandlerChangingAction = null;
thisAsIElement.HandlerChangingActionWithArgs = null;
thisAsIElement.HandlerChangedAction = null;
thisAsIElement.HandlerChangedActionWithArgs = null;
OnReset();
}

Expand Down
2 changes: 2 additions & 0 deletions src/MauiReactor/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal override void Reset()
thisAsIEntry.HorizontalTextAlignment = null;
thisAsIEntry.VerticalTextAlignment = null;
thisAsIEntry.ClearButtonVisibility = null;
thisAsIEntry.CompletedAction = null;
thisAsIEntry.CompletedActionWithArgs = null;
OnReset();
}

Expand Down
2 changes: 2 additions & 0 deletions src/MauiReactor/EntryCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ internal override void Reset()
thisAsIEntryCell.Keyboard = null;
thisAsIEntryCell.HorizontalTextAlignment = null;
thisAsIEntryCell.VerticalTextAlignment = null;
thisAsIEntryCell.CompletedAction = null;
thisAsIEntryCell.CompletedActionWithArgs = null;
OnReset();
}

Expand Down
2 changes: 2 additions & 0 deletions src/MauiReactor/FlyoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal override void Reset()
thisAsIFlyoutPage.IsGestureEnabled = null;
thisAsIFlyoutPage.IsPresented = null;
thisAsIFlyoutPage.FlyoutLayoutBehavior = null;
thisAsIFlyoutPage.IsPresentedChangedAction = null;
thisAsIFlyoutPage.IsPresentedChangedActionWithArgs = null;
OnReset();
}

Expand Down
14 changes: 14 additions & 0 deletions src/MauiReactor/GraphicsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ internal override void Reset()
base.Reset();
var thisAsIGraphicsView = (IGraphicsView)this;
thisAsIGraphicsView.Drawable = null;
thisAsIGraphicsView.StartHoverInteractionAction = null;
thisAsIGraphicsView.StartHoverInteractionActionWithArgs = null;
thisAsIGraphicsView.MoveHoverInteractionAction = null;
thisAsIGraphicsView.MoveHoverInteractionActionWithArgs = null;
thisAsIGraphicsView.EndHoverInteractionAction = null;
thisAsIGraphicsView.EndHoverInteractionActionWithArgs = null;
thisAsIGraphicsView.StartInteractionAction = null;
thisAsIGraphicsView.StartInteractionActionWithArgs = null;
thisAsIGraphicsView.DragInteractionAction = null;
thisAsIGraphicsView.DragInteractionActionWithArgs = null;
thisAsIGraphicsView.EndInteractionAction = null;
thisAsIGraphicsView.EndInteractionActionWithArgs = null;
thisAsIGraphicsView.CancelInteractionAction = null;
thisAsIGraphicsView.CancelInteractionActionWithArgs = null;
OnReset();
}

Expand Down
6 changes: 6 additions & 0 deletions src/MauiReactor/ImageButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ internal override void Reset()
thisAsIImageButton.Aspect = null;
thisAsIImageButton.IsOpaque = null;
thisAsIImageButton.Padding = null;
thisAsIImageButton.ClickedAction = null;
thisAsIImageButton.ClickedActionWithArgs = null;
thisAsIImageButton.PressedAction = null;
thisAsIImageButton.PressedActionWithArgs = null;
thisAsIImageButton.ReleasedAction = null;
thisAsIImageButton.ReleasedActionWithArgs = null;
OnReset();
}

Expand Down
12 changes: 12 additions & 0 deletions src/MauiReactor/ImageButton.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

namespace MauiReactor;

public partial class ImageButton<T>
{
partial void OnReset()
{
var thisAsIImageButton = (IImageButton)this;
System.Diagnostics.Debug.Assert(thisAsIImageButton.ClickedAction == null);
System.Diagnostics.Debug.Assert(thisAsIImageButton.ClickedActionWithArgs == null);
}
}

public partial class ImageButton
{
public ImageButton(string imageSource) => this.Source(imageSource);
public ImageButton(Uri imageSource) => this.Source(imageSource);


}

public partial class Component
Expand Down
Loading

0 comments on commit 74ad1b6

Please sign in to comment.