Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28533] Android: ListView scrollToItem always uses first section

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2021-09-10T09:28:34.000+0000
Affected Version/sRelease 9.3.1
Fix Version/sRelease 10.1.0
ComponentsAndroid
LabelsListView, android, regression
ReporterMichael Gangolf
AssigneeGary Mathews
Created2021-09-08T09:21:28.000+0000
Updated2021-09-10T09:28:34.000+0000

Description

The current ListView.scrollToItem always scrolls to the first section if there are multiple. I've tested 10.1.0 after https://github.com/appcelerator/titanium_mobile/pull/12762 was merged with this code:
const win = Ti.UI.createWindow();
const animation = { animated: true };
const toggle_animation = Ti.UI.createButton({ bottom: 20, title: animated: ${animation.animated} });

function createSection(sectionId, rows) {
	const section = Ti.UI.createListSection({
		headerTitle: Section ${sectionId}
	});
	const items = [];

	for (let i = 0; i < rows; i++) {
		items.push({
			properties: {
				title: ${sectionId} Row #${i},
				searchableText: Row #${i}
			}
		});
	}
	section.items = items;

	return section;
}
const listView = Ti.UI.createListView({ sections: [ createSection(0, 40),createSection(1, 40),createSection(2, 40) ] });

toggle_animation.addEventListener('click', e => {
	animation.animated = !animation.animated;
	toggle_animation.title = animated: ${animation.animated};
});

setInterval(_ => {
	const i = Math.floor(Math.random() * listView.sections[0].itemCount);
	listView.scrollToItem(1, i, animation);  // use second section
	console.log(scrollToItem: ${i});
}, 2000);

win.add([ listView, toggle_animation ]);
win.open();
(almost the same as in the ticket but with 3 sections and scrollToItem(1, random) It should scroll to the 2nd section, so rows with "1 - row..." should be the targets. But it is always going to "0 - row ..." items. SDK: 10.1.0 (compiled 9/8/2021) Android 11, Pixel 4 (device)

Comments

  1. Joshua Quick 2021-09-08

    [~michael], I'm pretty sure this is fixed in the following PR since we internally use scrollToItem() to handle tap-and-hold to start item selection. I'll need to double check. https://github.com/appcelerator/titanium_mobile/pull/12769
  2. Gary Mathews 2021-09-08

    [~michael] I pushed a fix for this into https://github.com/appcelerator/titanium_mobile/pull/12769, thanks for reporting this
  3. Michael Gangolf 2021-09-08

    [~gmathews] Awesome, thanks for the quick fix. Works fine (y)

JSON Source