From 4df52fbbb1cca735746f137c404974a0d545bc8c Mon Sep 17 00:00:00 2001 From: Jonathan Dick Date: Mon, 16 Mar 2020 09:54:24 -0400 Subject: [PATCH] Add some checking around android forms touch focus --- .../ZXingScannerViewRenderer.android.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ZXing.Net.Mobile.Forms/ZXingScannerViewRenderer.android.cs b/ZXing.Net.Mobile.Forms/ZXingScannerViewRenderer.android.cs index 71e071b..1735591 100644 --- a/ZXing.Net.Mobile.Forms/ZXingScannerViewRenderer.android.cs +++ b/ZXing.Net.Mobile.Forms/ZXingScannerViewRenderer.android.cs @@ -112,17 +112,32 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE break; } } + + volatile bool isHandlingTouch = false; public override bool OnTouchEvent(MotionEvent e) { - var x = e.GetX(); - var y = e.GetY(); - - if (zxingSurface != null) + if (!isHandlingTouch) { - zxingSurface.AutoFocus((int)x, (int)y); - System.Diagnostics.Debug.WriteLine("Touch: x={0}, y={1}", x, y); + isHandlingTouch = true; + + try + { + var x = e.GetX(); + var y = e.GetY(); + + if (Control != null) + { + Control.AutoFocusAsync((int)x, (int)y); + Logger.Info($"Touch: x={x}, y={y}"); + } + } + finally + { + isHandlingTouch = false; + } } + return base.OnTouchEvent(e); } }