Problem
Adding the eventListener of longpress to a TableViewRow does not fire the event.
Test Case
Make a project with the below app.js. Long press on the row and notice that the event never fires.
var win1 = Titanium.UI.createWindow({backgroundColor:'#000000'});
var row = Titanium.UI.createTableViewRow({height:'auto'});
var view = Titanium.UI.createView({backgroundColor:'red',width:'90%',height:'100%'});
row.add(view);
row.addEventListener('longpress', TableViewRowLongPress);
var table = Titanium.UI.createTableView();
table.appendRow(row);
win1.add(table);
function TableViewRowLongPress(evt)
{
Ti.API.info('****TableViewRow longpress');
}
win1.open();
More Information
The above Test Case is not normally how we add data to a TableView. When assigning the data property of the TableView to an array you do not have access to the TableViewRow to attach a longpress listener. What would really be nice is to have the longpress event handled by the TableView itself and have the same information passed in the evt parameter as the click event (ie. row, rowData).
Yes, please add longpress to TableView for Android and iOS (if you want to add/fix it to TableViewRow also, go ahead...but having it on TableView is more useful).
Shawn If you require this event for TableView, then please raise a ticket. Thank you
Shouldn't event propagation automatically fire longpress on the row, section, and TableView itself? Appcelerator documentation says _"Events automatically propagate to parent views"_.
Hey Ping, will this event propagate up to the TableView when you're done fixing it?
Another test case:
Testing steps: 1. Run the above code 2. Click/singletap/doubletap/doubleclick/longpress the blue/white/red area. Should see some output in the log. 3. Click/singletap/doubletap/doubleclick/longpress the green area. Should not see any output in the log.
Hey Shawn, events will propagate to the TableView after my fix.
That's good news, Ping! Here's a modification of the original testcase, specific to TableViews, to test that longpress propagates up from the TableViewRow to the TableView: {noformat} var win1 = Titanium.UI.createWindow({backgroundColor:'#000000'}); var row1 = Titanium.UI.createTableViewRow({height:'auto'}); var view1 = Titanium.UI.createView({backgroundColor:'red',width:'90%',height:'100%'}); row1.add(view1); var table1 = Titanium.UI.createTableView(); table1.appendRow(row1); win1.add(table1); table1.addEventListener('longpress', TableViewLongPress); function TableViewLongPress(evt) { Ti.API.info('****TableView recognized longpress on row # '+evt.index); } win1.open(); {noformat}
Tested with Droid 2.2.2 with 2.0.0.v20120312213243
After testing, I've noticed that on Android, "longclick" is the event that will be noticed (instead of "longpress") at the TableView level, and the event's properties are: index, rowData, source, and type. This works for me.
I don't think we're quite there yet. "longclick" will fire at the TableView level, and its event carries index, rowData, source, and type properties. "longpress" will fire at the View level, but not the TableView level. It needs to propagate up to the TableView level and have row-specifying properties on its event. It needs index, rowData, source, and type properties.
HD ticket: http://support.appcelerator.com/tickets/APP-843858 (for additional properties on the 'longpress' event).
Additional data for the longpress event is a new feature and not in the scope of this bug. There are already tickets (TIMOB-8795, TIMOB-8796) open for the new feature. Resolving this bug
Titanium Studio: 2.1.0.201206221045 & 2.0.2 Mobile SDK: 2.1.0.v20120622174154 OS: X Lion Device: Samsung Galaxy Can't reproduce. 1. Based on updates test case (Ping Wang added a comment - 02/Mar/12 3:57 PM) unable to reproduce the bug. Longpress event does get fired.
Re-opening to edit label.