Skip to content

Commit

Permalink
2.0.41 - Support for OnRender method returning null
Browse files Browse the repository at this point in the history
  • Loading branch information
adospace committed Jun 18, 2024
1 parent be1cb2a commit 169ffb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 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.40
Version: 2.0.41

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions src/MauiReactor/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ object IComponentWithProps.Props
{
if (_props != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException("Unable to set props on new component: Has Props been accessed from constructor?");
}

_props = (P)value;
Expand Down Expand Up @@ -346,7 +346,7 @@ object IComponentWithState.State
{
if (_state != null)
{
throw new InvalidOperationException();
throw new InvalidOperationException("Unable to set State on new component: Has State been accessed from constructor?");
}
_state = (S)value;
}
Expand Down
15 changes: 14 additions & 1 deletion src/MauiReactor/Layout.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ protected override void OnAddChild(VisualNode widget, BindableObject childContro

if (childControl is Microsoft.Maui.IView control)
{
NativeControl.Children.Insert(widget.ChildIndex, control);
//NOTE: Even if not advisable a component author could decide to returns
// null in the OnRender() overload.
// In that case the number of children in the NativeControl couldn't
// match the list of children in the visual tree.
// Let's tolerate it just appending the controls at the end of the list.
// OnRemoveChild() belowe soens't use the ChildIndex so no problem
if (widget.ChildIndex < NativeControl.Children.Count)
{
NativeControl.Children.Insert(widget.ChildIndex, control);
}
else
{
NativeControl.Children.Add(control);
}
}

base.OnAddChild(widget, childControl);
Expand Down

0 comments on commit 169ffb6

Please sign in to comment.