Skip to content

Commit

Permalink
feat: Add GestureRecognizers property to View and GestureElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamescaper committed Nov 13, 2024
1 parent dd834af commit 259a16b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public partial class GeneratedPropertyInfo
[
"Microsoft.Maui.IElement",
"Microsoft.Maui.Controls.BindableObject",
"Microsoft.Maui.Controls.IGestureRecognizer",
"Microsoft.Maui.Controls.ControlTemplate",
"Microsoft.Maui.Controls.DataTemplate",
"Microsoft.Maui.Graphics.IShape"
"Microsoft.Maui.Graphics.IShape",
];

private static readonly string[] NonContentTypes =
[
"Microsoft.Maui.Controls.FormattedString",
"Microsoft.Maui.Controls.ImageSource",
"Microsoft.Maui.Controls.ItemsLayout",
"Microsoft.Maui.Controls.Window",
"Microsoft.Maui.Controls.ItemsLayout"
];

public bool IsRenderFragmentProperty => Kind == GeneratedPropertyKind.RenderFragment;
Expand Down
28 changes: 28 additions & 0 deletions src/BlazorBindings.Maui/Elements/GestureElement.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BlazorBindings.Core;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using System.Threading.Tasks;

#pragma warning disable MBB001
Expand All @@ -24,10 +25,37 @@ static GestureElement()
RegisterAdditionalHandlers();
}

/// <summary>
/// Gets the list of recognizers that belong to the element.
/// </summary>
/// <value>
/// The list of recognizers that belong to the element.
/// </value>
[Parameter] public RenderFragment GestureRecognizers { get; set; }

public new MC.GestureElement NativeControl => (MC.GestureElement)((BindableObject)this).NativeControl;

protected override MC.GestureElement CreateNativeElement() => new();

protected override void HandleParameter(string name, object value)
{
switch (name)
{
case nameof(GestureRecognizers):
GestureRecognizers = (RenderFragment)value;
break;

default:
base.HandleParameter(name, value);
break;
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddListContentProperty<MC.GestureElement, MC.IGestureRecognizer>(builder, sequence++, GestureRecognizers, x => x.GestureRecognizers);
}

static partial void RegisterAdditionalHandlers();
}
Expand Down
5 changes: 5 additions & 0 deletions src/BlazorBindings.Maui/Elements/GestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace BlazorBindings.Maui.Elements;

public partial class GestureRecognizer : INonPhysicalChild
{
// This INonPhysicalChild staff was done to allow GestureElements to be the direct child of the element.
// However, not all elements support that (if they have no ChildContent property). Therefore. GestureElements property is added.
// This thing remains in order to preserve backward compatibility.
// Probably should be removed at some point.

void INonPhysicalChild.RemoveFromParent(object parentElement)
{
switch (parentElement)
Expand Down
14 changes: 14 additions & 0 deletions src/BlazorBindings.Maui/Elements/View.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BlazorBindings.Core;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Maui;
using System.Threading.Tasks;

Expand Down Expand Up @@ -37,6 +38,10 @@ static View()
/// Gets or sets the <see cref="T:Microsoft.Maui.Controls.LayoutOptions" /> that define how the element gets laid out in a layout cycle.
/// </summary>
[Parameter] public MC.LayoutOptions? VerticalOptions { get; set; }
/// <summary>
/// The collection of gesture recognizers associated with this view.
/// </summary>
[Parameter] public RenderFragment GestureRecognizers { get; set; }

public new MC.View NativeControl => (MC.View)((BindableObject)this).NativeControl;

Expand Down Expand Up @@ -66,13 +71,22 @@ protected override void HandleParameter(string name, object value)
NativeControl.VerticalOptions = VerticalOptions ?? (MC.LayoutOptions)MC.View.VerticalOptionsProperty.DefaultValue;
}
break;
case nameof(GestureRecognizers):
GestureRecognizers = (RenderFragment)value;
break;

default:
base.HandleParameter(name, value);
break;
}
}

protected override void RenderAdditionalElementContent(RenderTreeBuilder builder, ref int sequence)
{
base.RenderAdditionalElementContent(builder, ref sequence);
RenderTreeBuilderHelper.AddListContentProperty<MC.View, MC.IGestureRecognizer>(builder, sequence++, GestureRecognizers, x => x.GestureRecognizers);
}

static partial void RegisterAdditionalHandlers();
}
}

0 comments on commit 259a16b

Please sign in to comment.