[TIMOB-28533] Android: ListView scrollToItem always uses first section
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2021-09-10T09:28:34.000+0000 |
| Affected Version/s | Release 9.3.1 |
| Fix Version/s | Release 10.1.0 |
| Components | Android |
| Labels | ListView, android, regression |
| Reporter | Michael Gangolf |
| Assignee | Gary Mathews |
| Created | 2021-09-08T09:21:28.000+0000 |
| Updated | 2021-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)
[~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[~michael] I pushed a fix for this into https://github.com/appcelerator/titanium_mobile/pull/12769, thanks for reporting this
[~gmathews] Awesome, thanks for the quick fix. Works fine (y)