Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28552] Android: ListView "move" event can return wrong "itemIndex" and is missing "target*" properties

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2021-10-20T03:12:44.000+0000
Affected Version/sRelease 9.3.0
Fix Version/sRelease 10.2.0
ComponentsAndroid
LabelsListView, android, editing, move, parity
ReporterJoshua Quick
AssigneeJoshua Quick
Created2021-10-12T18:20:25.000+0000
Updated2021-10-20T03:12:44.000+0000

Description

*Summary:* ListView "move" event has the following issues on Android... * The "itemIndex" will return the wrong index if you drag-and-drop the ListItem slowly. The index changes as the list items shift between the dragged item. * The "targetSection", "targetSectionIndex", and "targetItemIndex" are undefined. This means we don't know where the ListItem was moved to in the list. *Steps to reproduce:*

Build and run the below on Android.

Tap and hold the top most row. _(This is "itemIndex" 0.)_

Slowly drag it to the bottom of the section and release.

Notice the log states "itemIndex" is 2 when it should be 0.

function createListViewSection(sectionTitle) {
	const items = [];
	for (let index = 1; index <= 4; index++) {
		items.push({
			properties: {
				title: Row ${index},
				canEdit: false,
				canMove: true,
			},
		});
	}
	const section = Ti.UI.createListSection({
		headerTitle: sectionTitle,
		items: items,
	});
	return section;
}

const window = Ti.UI.createWindow();
const listView = Ti.UI.createListView({
	sections: [
		createListViewSection("Section 1"),
		createListViewSection("Section 2"),
	],
	allowsSelectionDuringEditing: false,
	allowsMultipleSelectionDuringEditing: false,
	editing: true,
});
listView.addEventListener("move", (e) => {
	const data = {
		sectionIndex: e.sectionIndex,
		itemIndex: e.itemIndex,
		targetSectionIndex: e.targetSectionIndex,
		targetItemIndex: e.targetItemIndex,
	};
	console.log(@@@ "move" event: ${JSON.stringify(data)});
});
window.add(listView);
window.open();

Comments

  1. Joshua Quick 2021-10-14

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/13120

JSON Source