FMX AppBar Touch Sensitivity Tip

FMX Android often misses tap events, even if a control gives a visual indication that a tap occurred. This can become frustrating for the user, requiring them to tap two, sometimes three times.

I had a suspicion that FMX was receiving the touch event correctly, but had problems identifying less precise user gestures. I had a similar issue with swipe left and swipe right, if the swipe is not perfectly horizontal it is not recognized. Since people swipe on a slight angle, these gestures weren’t detected. Again, very frustrating for the user, as noted on StackOverflow:

I managed to solve this by overriding the OnTouch event in the MainForm and detecting a swipe from a minimum series of events. Taking another look, I noticed the MainForm does indeed receive every touch event. The problem is in the FMX gesture detection code. Similar to the swipe solution, if the AppBar’s SpeedButton(s) fail to detect a tap, I manually look for the touch event.

For example, a touch event within Y< 56 and and X < 56 can be used to trigger a back button manually. In Material Design, the back button has margins of 16, and a height and width of 24, from where we get the X and Y values of 56. Given the AppBar has a height of 56, any event with a start or end Y value of less than 56 can reasonably be assumed to indicate the user is trying to tap on the AppBar. The code then delegates to the AppBar which activates the button at position X.

Here is the part of the MainForm’s OnTouch function which looks for the missed tap gesture on the AppBar – it certainly can be improved but it is working well for my current needs; it is only executed for single touch events when the target control’s gesture detection fails, and other than the AppBar, any other client has to subscribe to this service:

I hope this tip helps.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s