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 | Show 6 more comments1 Answer
Reset to default 0I 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>
OnPinchUpdated
handler? – Stephen Quan Commented Feb 17 at 0:55