Ajay Verma
Ajay Verma

Reputation: 584

How to open Menu Options in .NET MAUI on long press

How to open Menu Options in .NET MAUI on long press. Currently iPhone does this within photos like below video:

https://drive.google.com/file/d/1is7DjGFNWERy1xCx08j__kjc1ruQm1A-/view?usp=sharing

I want to implement this on Android and iOS devices. I am using CollectionView for rendering elements.

Is it possible in using .NET MAUI?

Upvotes: 0

Views: 568

Answers (1)

Liyun Zhang - MSFT
Liyun Zhang - MSFT

Reputation: 14509

There is a proposal to include this in the MAUI Community Toolkit: [Proposal] TouchEffect.

And you requirement is implementing this on the Android and iOS. So you can try to use the platform code to do that:

For the android, you can use the ImageView's Long Click event to do that. Such as:

#if ANDROID
   (image.Handler.PlatformView as Android.Widget.ImageView).LongClick +=(s,e)=>
   {
    //do something
   }
#end if

And you can also declare a View.OnLongClickListener and then set the it for the image. Such as:

 public class MyListener : Java.Lang.Object, Android.Views.View.IOnLongClickListener
    {
        public bool OnLongClick(Android.Views.View? v)
        {
           //do what you want here
        }
    }
=====
#if ANDROID
   (image.Handler.PlatformView as Android.Widget.ImageView).SetOnLongClickListener(new MyListener());
#end if

And for the ios, you can use the UILongPressGestureRecognizer:

#if IOS    
    (image.handler.PlatformView as UIKit.UIImageView).UserInteractionEnabled = true;  
    (image.handler.PlatformView as UIKit.UIImageView).AddGestureRecognizer(new UILongPressGestureRecognizer(MethodName()));  
#endif  

And the effect after the long press, you can use the popup to do it.

Upvotes: 0

Related Questions