最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

MAUI: PinchGestureRecognizer blocks tap event of editor - Stack Overflow

programmeradmin3浏览0评论

i added the PinchGestureRecognizer like this to the MAUI editor XAML. The pinch works but the editor does not receive tap event anymore and is basically dead. I already explicitly added the tap recognizer but most of the advanced features (events) of the Editor are still dead, like putting cursor to where user taps inside text.

<Editor.GestureRecognizers>
    <PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</Editor.GestureRecognizers>

Edit: I have the issue via USB-Cable Debugging on an Samsung Galaxy S24, Android 14

i added the PinchGestureRecognizer like this to the MAUI editor XAML. The pinch works but the editor does not receive tap event anymore and is basically dead. I already explicitly added the tap recognizer but most of the advanced features (events) of the Editor are still dead, like putting cursor to where user taps inside text.

<Editor.GestureRecognizers>
    <PinchGestureRecognizer PinchUpdated="OnPinchUpdated" />
</Editor.GestureRecognizers>

Edit: I have the issue via USB-Cable Debugging on an Samsung Galaxy S24, Android 14

Share Improve this question edited Feb 16 at 18:05 sba asked Feb 16 at 9:30 sbasba 4114 silver badges11 bronze badges 11
  • on which Platform? – Bhavanesh N Commented Feb 16 at 14:06
  • @BhavaneshN it´s on Android. Added that info to the original post. – sba Commented Feb 16 at 18:06
  • What if you called Focus() in your OnPinchUpdated handler? – Stephen Quan Commented Feb 17 at 0:55
  • @sba seems like a bug .. i raised a new one github/dotnet/maui/issues/27831 – Bhavanesh N Commented Feb 17 at 3:06
  • @StephenQuan i even have to call Focus() which seems to be a bug as well. I shouldn´t need to call Focus() when Editor is going into input mode. – sba Commented Feb 17 at 9:31
 |  Show 6 more comments

1 Answer 1

Reset to default 0

I create a EditorHandler and re-implement the touch event.

The number of touch points is used to distinguish whether it is a click event. If it is, the touch event is executed. If there is more than one touchpoint, the click event is not executed.

using Android.Views;
using AndroidX.AppCompat.Widget;
using Microsoft.Maui.Handlers;
 
namespace MauiApp2.Platforms.Android
{
    public class CustomEditorHandler : EditorHandler
    {
        protected override void ConnectHandler(AppCompatEditText nativeView)
        {
            base.ConnectHandler(nativeView);
 
            //add touch event
            nativeView.Touch += NativeView_Touch; ;
        }
 
        protected override void DisconnectHandler(AppCompatEditText nativeView)
        {
            base.DisconnectHandler(nativeView);
            nativeView.Touch -= NativeView_Touch; ;
        }
        private void NativeView_Touch(object? sender, global::Android.Views.View.TouchEventArgs e)
        {
            if (sender is AppCompatEditText nativeView)
            {
                // check the click event
                if (e.Event.Action == MotionEventActions.Down)
                {
                    // request focus
                    nativeView.RequestFocus();
                }
 
                // transfer the click event
                if (e.Event.PointerCount > 1)
                {
                    // if Pinch guesture,prevent this operation
                    e.Handled = false;
                }
                else
                {
                    // if click, do it
                    e.Handled = true;
                }
            }
        }
 
    }
}

Then, I create a class that extend the Editor.

public class CustomEditor : Editor
{
    
}

In the end, I register this custom editor in the MauiProgram.cs.

.ConfigureMauiHandlers(handlers =>
                   {
#if ANDROID
                       handlers.AddHandler(typeof(CustomEditor), typeof(MauiApp2.Platforms.Android.CustomEditorHandler));
 
#endif
                   }); ;

I add following code to test it, it is working in my side.

<local:CustomEditor>
    <local:CustomEditor.GestureRecognizers>
        <PinchGestureRecognizer PinchUpdated="PinchGestureRecognizer_PinchUpdated" />
       <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"> 
         </TapGestureRecognizer>
     </local:CustomEditor.GestureRecognizers>
</local:CustomEditor>
发布评论

评论列表(0)

  1. 暂无评论