Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28337] Android: ListView properties missing in "longpress" event in Alloy as of 9.3.0

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2021-02-10T16:35:29.000+0000
Affected Version/sRelease 9.3.1, Release 10.0.0
Fix Version/sRelease 9.3.2
ComponentsAndroid
Labelslistview, longpress, regression
ReporterHans Knöchel
AssigneeGary Mathews
Created2021-02-05T20:42:00.000+0000
Updated2021-02-12T08:48:30.000+0000

Description

When using the "longpress" event on the Android ListView in 9.3.0+, the itemIndex / sectionIndex are not supplied via the event when the longpress occured on a child view of the list item template. I don't have an isolated test case so far, but it should be reproducible on any custom-templates test case that adds the "longpress" event to the view wrapper. The same used to work on both iOS and Android. What I can share immediately is the Alloy sample:
<Alloy>
	<ListView id="listView" defaultItemTemplate="MyCell">
		<Templates>
			<ItemTemplate name="MyCell">
				<View height="43" onLongpress="onLongPress">
					<ImageView bindId="image" />
					<Label bindId="titleLabel" />
				</View>
			</ItemTemplate>
		</Templates>
	</ListView>
</Alloy>
Important to note is that the longpress event is added to the item template, not the list view itself as this used to be the only way to handle this. If there are better ways, let me know! *EDIT*: Just checked it: The longpress event does not work on the ListView at all (like the itemclick and others), so the above is the only feasible workaround thats now also broken :(

Comments

  1. Hans Knöchel 2021-02-08

    Thanks for looking into this Gary :) Many thanks for this amazing work!
  2. Gary Mathews 2021-02-09

    [~hknoechel] I'm having trouble reproducing this in JS, adding an event listener to a child label will inherit sectionIndex and itemIndex etc.. correctly.
       const win = Ti.UI.createWindow({
           backgroundColor: 'gray'
       });
       const listView = Ti.UI.createListView({
           backgroundColor: 'white',
           templates: {
               template: {
                   properties: {
                       borderRadius: 16,
                       height: 50
                   },
                   childTemplates: [{
                       type: 'Ti.UI.Label',
                       bindId: 'label',
                       events: {
                       	longpress (e) {
                       		console.log('longpress: ' + JSON.stringify(Object.keys(e), null, 2));
                       	}
                       },
                       properties: {
                           color: 'white'
                       }
                   }]
               }
           },
           defaultItemTemplate: 'template'
       });
       listView.sections = [
           Ti.UI.createListSection({
               items: [{
                       properties: {
                           backgroundColor: 'red'
                       },
                       label: {
                           text: 'Red'
                       }
                   },
                   {
                       properties: {
                           backgroundColor: 'green'
                       },
                       label: {
                           text: 'Green'
                       }
                   },
                   {
                       properties: {
                           backgroundColor: 'blue'
                       },
                       label: {
                           text: 'Blue'
                       }
                   },
                   {
                       properties: {
                           backgroundColor: 'yellow'
                       },
                       label: {
                           text: 'Yellow'
                       }
                   },
                   {
                       properties: {
                           backgroundColor: 'cyan'
                       },
                       label: {
                           text: 'Cyan'
                       }
                   },
                   {
                       properties: {
                           backgroundColor: 'pink'
                       },
                       label: {
                           text: 'Pink'
                       }
                   },
               ]
           })
       ];
       
       win.add(listView);
       win.open();
       
    I'll look into what Alloy is doing, as it may not be making use of the events property in the template.
  3. Gary Mathews 2021-02-09

    master: https://github.com/appcelerator/titanium_mobile/pull/12456
  4. Lokesh Choudhary 2021-02-09

    FR Passed. Waiting for jenkins.
  5. Rodrigo Farfán 2021-02-12

    This was also reported in TIMOB-28291.
  6. Hans Knöchel 2021-02-12

    Thanks Rodrigo! I believe now it's fully fixed. You can try the latest 9.3.2 version (ti sdk install -b 9_3_X)!

JSON Source