Skip to content

Commit

Permalink
Fix PointerGesture CommandParameter properties (#15863)
Browse files Browse the repository at this point in the history
* Fix PointerGesture CommandParameter properties

* Add tests
  • Loading branch information
rachelkang authored Jun 29, 2023
1 parent 31e43f7 commit efd3a5a
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
<Label x:Name="positionLabel" Text="Hover above label to reveal pointer position"/>
<Label x:Name="positionToWindow" />
<Label x:Name="positionToThisLabel" />

<Label x:Name="colorfulHoverLabel" Text="Hover me green!" FontSize="24" />
<Label Text="Hover above label to make it turn green" />
</StackLayout>
</views:BasePage>
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Pages
{
public partial class PointerGestureGalleryPage
{
Command _hoverEnterCommand;

public PointerGestureGalleryPage()
{
InitializeComponent();

_hoverEnterCommand = new Command<Color>(HandleHoverEnterCommand);

var colorfulHoverEnterGesture = new PointerGestureRecognizer
{
PointerEnteredCommand = _hoverEnterCommand,
PointerEnteredCommandParameter = Colors.Green
};
colorfulHoverLabel.GestureRecognizers.Add(colorfulHoverEnterGesture);
}

void HoverBegan(object sender, PointerEventArgs e)
Expand All @@ -26,5 +38,10 @@ void HoverMoved(object sender, PointerEventArgs e)
positionToWindow.Text = $"Pointer position inside window: {e.GetPosition(null)}";
positionToThisLabel.Text = $"Pointer position relative to this label: {e.GetPosition(positionToThisLabel)}";
}

void HandleHoverEnterCommand(Color hoverColor)
{
colorfulHoverLabel.TextColor = hoverColor;
}
}
}
12 changes: 6 additions & 6 deletions src/Controls/src/Core/PointerGestureRecognizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public ICommand PointerEnteredCommand
/// <summary>
/// Identifies the PointerEnteredCommandParameter bindable property.
/// </summary>
public ICommand PointerEnteredCommandParameter
public object PointerEnteredCommandParameter
{
get { return (ICommand)GetValue(PointerEnteredCommandParameterProperty); }
get { return GetValue(PointerEnteredCommandParameterProperty); }
set { SetValue(PointerEnteredCommandParameterProperty, value); }
}

Expand All @@ -92,9 +92,9 @@ public ICommand PointerExitedCommand
/// <summary>
/// Identifies the PointerExitedCommandParameter bindable property.
/// </summary>
public ICommand PointerExitedCommandParameter
public object PointerExitedCommandParameter
{
get { return (ICommand)GetValue(PointerExitedCommandParameterProperty); }
get { return GetValue(PointerExitedCommandParameterProperty); }
set { SetValue(PointerExitedCommandParameterProperty, value); }
}

Expand All @@ -110,9 +110,9 @@ public ICommand PointerMovedCommand
/// <summary>
/// Identifies the PointerMovedCommandParameter bindable property.
/// </summary>
public ICommand PointerMovedCommandParameter
public object PointerMovedCommandParameter
{
get { return (ICommand)GetValue(PointerMovedCommandParameterProperty); }
get { return GetValue(PointerMovedCommandParameterProperty); }
set { SetValue(PointerMovedCommandParameterProperty, value); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ override Microsoft.Maui.Controls.Handlers.Items.ItemsViewHandler<TItemsView>.Get
override Microsoft.Maui.Controls.Handlers.Items.ItemsViewHandler<TItemsView>.PlatformArrange(Microsoft.Maui.Graphics.Rect frame) -> void
Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool
Microsoft.Maui.Controls.Platform.ShapesExtensions
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool
Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool
Microsoft.Maui.Controls.Shapes.Shape.~Shape() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.FlyoutOve
Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.FlyoutOverlapsDetailsInPopoverMode.set -> void
Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool
Microsoft.Maui.Controls.Platform.ShapesExtensions
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool
Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool
Microsoft.Maui.Controls.Shapes.Shape.~Shape() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.FlyoutOve
Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.FlyoutOverlapsDetailsInPopoverMode.set -> void
Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool
Microsoft.Maui.Controls.Platform.ShapesExtensions
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool
Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool
Microsoft.Maui.Controls.Shapes.Shape.~Shape() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ Microsoft.Maui.Controls.Border.~Border() -> void
Microsoft.Maui.Controls.IWindowCreator
Microsoft.Maui.Controls.IWindowCreator.CreateWindow(Microsoft.Maui.Controls.Application! app, Microsoft.Maui.IActivationState? activationState) -> Microsoft.Maui.Controls.Window!
Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool
Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool
Microsoft.Maui.Controls.VisualElement.~VisualElement() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Microsoft.Maui.Controls.IWindowCreator
Microsoft.Maui.Controls.IWindowCreator.CreateWindow(Microsoft.Maui.Controls.Application! app, Microsoft.Maui.IActivationState? activationState) -> Microsoft.Maui.Controls.Window!
Microsoft.Maui.Controls.Platform.CollectionViewExtensions
Microsoft.Maui.Controls.Platform.ShapesExtensions
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Handlers.Items.StructuredItemsViewHandler<TItemsView>.~StructuredItemsViewHandler() -> void
override Microsoft.Maui.Controls.Handlers.BoxViewHandler.NeedsContainer.get -> bool
Microsoft.Maui.Controls.Handlers.BoxViewHandler
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Microsoft.Maui.Controls.Border.~Border() -> void
Microsoft.Maui.Controls.IWindowCreator
Microsoft.Maui.Controls.IWindowCreator.CreateWindow(Microsoft.Maui.Controls.Application! app, Microsoft.Maui.IActivationState? activationState) -> Microsoft.Maui.Controls.Window!
Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool
Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool
Microsoft.Maui.Controls.Shapes.Shape.~Shape() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Microsoft.Maui.Controls.Border.~Border() -> void
Microsoft.Maui.Controls.IWindowCreator
Microsoft.Maui.Controls.IWindowCreator.CreateWindow(Microsoft.Maui.Controls.Application! app, Microsoft.Maui.IActivationState? activationState) -> Microsoft.Maui.Controls.Window!
Microsoft.Maui.Controls.LayoutOptions.Equals(Microsoft.Maui.Controls.LayoutOptions other) -> bool
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> object!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerEnteredCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerExitedCommandParameter.get -> System.Windows.Input.ICommand!
*REMOVED*Microsoft.Maui.Controls.PointerGestureRecognizer.PointerMovedCommandParameter.get -> System.Windows.Input.ICommand!
Microsoft.Maui.Controls.Region.Equals(Microsoft.Maui.Controls.Region other) -> bool
Microsoft.Maui.Controls.Shapes.Matrix.Equals(Microsoft.Maui.Controls.Shapes.Matrix other) -> bool
Microsoft.Maui.Controls.Shapes.Shape.~Shape() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,51 @@ public void ClearingGestureRecognizers()
Assert.Null(gestureRecognizer.Parent);
}

[Fact]
public void PointerEnteredCommandFires()
{
var gesture = new PointerGestureRecognizer();
var parameter = new object();
object commandExecuted = null;
Command cmd = new Command(() => commandExecuted = parameter);

gesture.PointerEnteredCommand = cmd;
gesture.PointerEnteredCommandParameter = parameter;
cmd?.Execute(parameter);

Assert.Equal(commandExecuted, parameter);
}

[Fact]
public void PointerExitedCommandFires()
{
var gesture = new PointerGestureRecognizer();
var parameter = new object();
object commandExecuted = null;
Command cmd = new Command(() => commandExecuted = parameter);

gesture.PointerExitedCommand = cmd;
gesture.PointerExitedCommandParameter = parameter;
cmd?.Execute(parameter);

Assert.Equal(commandExecuted, parameter);
}

[Fact]
public void PointerMovedCommandFires()
{
var gesture = new PointerGestureRecognizer();
var parameter = new object();
object commandExecuted = null;
Command cmd = new Command(() => commandExecuted = parameter);

gesture.PointerMovedCommand = cmd;
gesture.PointerMovedCommandParameter = parameter;
cmd?.Execute(parameter);

Assert.Equal(commandExecuted, parameter);
}

VisualStateGroupList AddPointerOverVisualState(VisualElement visualElement)
{
VisualStateGroupList visualStateGroups = new VisualStateGroupList();
Expand Down

0 comments on commit efd3a5a

Please sign in to comment.