05 May 2013

A little warning: you should not use click or dblclick when you are building an application for mobile devices with Appcelerator Titanium. You'll know why if you read more:) I begin this article saying this because most of the examples you'll see in docs or tutorials uses the click event (at the time I am writing this article) and can be misleading.

You can test the gestures with a small Titanium app I've done. You can find the code on github.


Which are the user gestures and their corresponding eventname in Appcelerator Titanium API?

Real gestures and the associated events when all events have been bound to the same view:


The difference between click and singletap on a mobile

The difference is how they react to a real longpress from a user. 'Singletap' won't be fired when the user keeps his finger on the screen for a while and then removes it. On the contrary 'click' will be fired once the user lift his fingers.

The difference between longclick and longpress on a mobile

If the user touches and moves its finger on the screen, longclick will be fired after a while. longpress won't.

Events that might lead to unexpected results when added to the same view:

Better UI response for the user:

While the natural way of thinking would be to add the classic "click" or "singletap" on a button, these events are fired after that the user has lift his/her finger. This takes some milliseconds to the user actually, (ninjas might be faster).

But think of it as switching the light on, usually you don't have to remove your finger before you get the light.

So, let's talk about "touchstart": it is fired as soon as the user touch the button / view. Binding some function to this event will provide an interface that looks more responsive. (a few milliseconds matter, try it :) Obviously, to avoid problems you have to know how the users will use your app, so remember that binding touchstart and another event might result in a conflict since touchstart will always be fired first.

note: while the above is true for "single type" event, when using dblclick / doubletap, those events are fired when the user touches the screen the second time. So there is not this "wait for the finger to be lifted" that click/singletap events have.


The official documentation and a good reference to learn about handling events in Appcelerator Titanium