Skip to content

Commit

Permalink
Add some checking around android forms touch focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth authored Mar 16, 2020
1 parent 5ac732a commit 4df52fb
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ZXing.Net.Mobile.Forms/ZXingScannerViewRenderer.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 4df52fb

Please sign in to comment.