Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Added long press event #851
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Mar 12, 2021
1 parent 6e6a28f commit 3a7c634
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Xamarin.CommunityToolkit.Effects
{
public class LongPressCompletedEventArgs : EventArgs
{
internal LongPressCompletedEventArgs(object? parameter)
=> Parameter = parameter;

public object? Parameter { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ internal void HandleLongPress(TouchEffect sender)
{
sender.HandleUserInteraction(TouchInteractionStatus.Completed);
sender.LongPressCommand?.Execute(sender.LongPressCommandParameter ?? sender.CommandParameter);
sender.RaiseLongPressCompleted();
});
if (Device.IsInvokeRequired)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class TouchEffect : RoutingEffect
remove => weakEventManager.RemoveEventHandler(value);
}

public event EventHandler<LongPressCompletedEventArgs> LongPressCompleted
{
add => weakEventManager.AddEventHandler(value);
remove => weakEventManager.RemoveEventHandler(value);
}

public static readonly BindableProperty IsAvailableProperty = BindableProperty.CreateAttached(
nameof(IsAvailable),
typeof(bool),
Expand Down Expand Up @@ -1156,6 +1162,9 @@ internal void RaiseHoverStatusChanged()
internal void RaiseCompleted()
=> weakEventManager.RaiseEvent(Element, new TouchCompletedEventArgs(CommandParameter), nameof(Completed));

internal void RaiseLongPressCompleted()
=> weakEventManager.RaiseEvent(Element, new LongPressCompletedEventArgs(LongPressCommandParameter ?? CommandParameter), nameof(LongPressCompleted));

internal void ForceUpdateState(bool animated = true)
{
if (Element == null)
Expand Down

0 comments on commit 3a7c634

Please sign in to comment.