Pixiview/Gallery.Android/Effects/LongPressEffectImplement.cs
2021-08-04 10:27:41 +08:00

50 lines
1.3 KiB
C#

using Gallery.Droid.Effects;
using Gallery.Utils;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using static Android.Views.View;
[assembly: ResolutionGroupName("Gallery")]
[assembly: ExportEffect(typeof(LongPressEffectImplement), "LongPressEffect")]
namespace Gallery.Droid.Effects
{
public class LongPressEffectImplement : PlatformEffect
{
private bool attached;
protected override void OnAttached()
{
if (!attached)
{
attached = true;
Control.LongClick += Container_LongClick;
}
}
protected override void OnDetached()
{
if (attached)
{
attached = false;
Control.LongClick -= Container_LongClick;
}
}
private void Container_LongClick(object sender, LongClickEventArgs e)
{
var element = Element;
if (element != null)
{
var command = LongPressEffect.GetCommand(element);
if (command != null)
{
e.Handled = true;
var o = LongPressEffect.GetCommandParameter(element);
command.Execute(o);
}
}
}
}
}