Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Gesture Recognizers #70

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BlazorBindings.Core/INonPhysicalChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public interface INonPhysicalChild
/// This is called when this component would otherwise be removed from a parent container.
/// This is useful so that this component can unapply its effects from parent element.
/// </summary>
void Remove();
void RemoveFromParent(object parentElement);
}
}
34 changes: 31 additions & 3 deletions src/BlazorBindings.Maui/Elements/GestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,41 @@
// Licensed under the MIT license.

using BlazorBindings.Core;
using BlazorBindings.Maui.Elements.Handlers;
using System;
using MC = Microsoft.Maui.Controls;

namespace BlazorBindings.Maui.Elements
{
public class GestureRecognizer : NativeControlComponentBase
public partial class GestureRecognizer : INonPhysicalChild
{
public MC.GestureRecognizer NativeControl => (ElementHandler as GestureRecognizerHandler)?.GestureRecognizerControl;
void INonPhysicalChild.RemoveFromParent(object parentElement)
{
switch (parentElement)
{
case MC.View view:
view.GestureRecognizers.Remove(NativeControl);
break;
case MC.GestureElement gestureElement:
gestureElement.GestureRecognizers.Remove(NativeControl);
break;
default:
throw new InvalidOperationException($"Gesture of type {NativeControl.GetType().Name} can't be removed from parent of type {parentElement.GetType().FullName}.");
}
}

void INonPhysicalChild.SetParent(object parentElement)
{
switch (parentElement)
{
case MC.View view:
view.GestureRecognizers.Add(NativeControl);
break;
case MC.GestureElement gestureElement:
gestureElement.GestureRecognizers.Add(NativeControl);
break;
default:
throw new InvalidOperationException($"Gesture of type {NativeControl.GetType().Name} can't be added to parent of type {parentElement.GetType().FullName}.");
}
}
}
}
29 changes: 29 additions & 0 deletions src/BlazorBindings.Maui/Elements/GestureRecognizer.generated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated>
// This code was generated by a BlazorBindings.Maui component generator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>

using BlazorBindings.Core;
using MC = Microsoft.Maui.Controls;
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;

namespace BlazorBindings.Maui.Elements
{
public partial class GestureRecognizer : Element
{
static GestureRecognizer()
{
RegisterAdditionalHandlers();
}

public new MC.GestureRecognizer NativeControl => (MC.GestureRecognizer)((Element)this).NativeControl;

protected override MC.Element CreateNativeElement() => new MC.GestureRecognizer();


static partial void RegisterAdditionalHandlers();
}
}
10 changes: 3 additions & 7 deletions src/BlazorBindings.Maui/Elements/GridCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,11 @@ public int GetChildIndex(MC.Element child)

void INonPhysicalChild.SetParent(object parentElement)
{
if (parentElement is not MC.Grid parentGrid)
{
throw new ArgumentException($"Expected parent to be of type {typeof(MC.Grid).FullName} but it is of type {parentElement?.GetType().FullName}.", nameof(parentElement));
}

_parentGrid = parentGrid;
_parentGrid = parentElement as MC.Grid
?? throw new ArgumentException($"Expected parent to be of type {typeof(MC.Grid).FullName} but it is of type {parentElement?.GetType().FullName}.", nameof(parentElement));
}

void INonPhysicalChild.Remove()
void INonPhysicalChild.RemoveFromParent(object parentElement)
{
if (_parentGrid != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

using BlazorBindings.Core;
using System;
using MC = Microsoft.Maui.Controls;

namespace BlazorBindings.Maui.Elements.Handlers
Expand All @@ -15,24 +14,21 @@ public abstract class BaseAttachedPropertiesHandler : IMauiElementHandler, INonP
protected MC.BindableObject Target { get; private set; }

public abstract void ApplyAttribute(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName);
public abstract void Remove();
public abstract void RemoveFromParent();

public void SetParent(object parentElement)
void INonPhysicalChild.SetParent(object parentElement)
{
Target = (MC.BindableObject)parentElement;
}

void INonPhysicalChild.RemoveFromParent(object parentElement)
{
RemoveFromParent();
}

// Because this is a 'fake' element, all matters related to physical trees
// should be no-ops.
public MC.Element ElementControl => null;
public object TargetElement => null;
public bool IsParented() => false;

public void SetParent(MC.Element parent)
{
// This should never get called. Instead, INonPhysicalChild.SetParent() implemented
// in this class should get called.
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void SetParent(object parentElement)
_parent = (TElementType)parentElement;
}

public void Remove()
public void RemoveFromParent(object parentElement)
{
// Because this Handler is used internally only, this method is no-op.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void SetParent(object parentElement)
_setPropertyAction(parent, controlTemplate);
}

public void Remove()
public void RemoveFromParent(object parentElement)
{
// Because this Handler is used internally only, this method is no-op.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void SetParent(object parentElement)
_setPropertyAction(parent, dataTemplate);
}

public void Remove()
public void RemoveFromParent(object parentElement)
{
// Because this Handler is used internally only, this method is no-op.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void SetParent(object parentElement)
_setPropertyAction(parent, dataTemplate);
}

public void Remove()
public void RemoveFromParent(object parentElement)
{
// Because this Handler is used internally only, this method is no-op.
}
Expand Down
54 changes: 0 additions & 54 deletions src/BlazorBindings.Maui/Elements/Handlers/EventManager.cs

This file was deleted.

26 changes: 0 additions & 26 deletions src/BlazorBindings.Maui/Elements/Handlers/EventRegistration.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void SetParent(object parentElement)
_propertyItems = _listPropertyAccessor((TElementType)parentElement);
}

public void Remove()
public void RemoveFromParent(object parentElement)
{
// Because this Handler is used internally only, this method is no-op.
}
Expand Down
Loading