Skip to content

fix(listview): correct item template resolution in sectioned ListView#11184

Open
VeinDevTtv wants to merge 2 commits intoNativeScript:mainfrom
VeinDevTtv:fix/sectioned-listview-item-template-selector
Open

fix(listview): correct item template resolution in sectioned ListView#11184
VeinDevTtv wants to merge 2 commits intoNativeScript:mainfrom
VeinDevTtv:fix/sectioned-listview-item-template-selector

Conversation

@VeinDevTtv
Copy link
Copy Markdown
Contributor

@VeinDevTtv VeinDevTtv commented Apr 19, 2026

PR Checklist

What is the current behavior?

When using a sectioned ListView with multiple item templates and an itemTemplateSelector, the wrong template is returned for items. _getItemTemplate(index) calls _getDataItem(index) which reads directly from this.items[index]. In sectioned mode, this.items is an array of section objects (e.g. { title, items }), so indexing it by row number returns a section object instead of the actual row data item. The itemTemplateSelector then receives the wrong data and resolves the wrong template key, causing incorrect cell types to be recycled and rendered.

On iOS, _prepareCell contained a broken absoluteIndex workaround that summed up items across sections and fed that offset back into the same flat _getItemTemplate — which still hits this.items[absoluteIndex] on the sectioned top-level array, returning another section object.

What is the new behavior?

A new method _getItemTemplateInSection(section, index) is added to ListViewBase. It uses _getDataItemInSection to correctly fetch the row item from within its section, and _getItemsInSection to pass the section's own items array to the itemTemplateSelector — matching the same contract that _prepareItemInSection uses for binding contexts.

All call sites that select a template for a sectioned row are updated to use this method:

  • iOS: tableViewCellForRowAtIndexPath, tableViewHeightForRowAtIndexPath, and _prepareCell (replacing the broken absoluteIndex workaround).
  • Android: getItemViewType and _createItemView.

Fixes #11133.

When using a sectioned ListView with multiple item templates, the template
returned by _getItemTemplate could be wrong because it calls _getDataItem
which does not consider the sectioned data structure. This means the
itemTemplateSelector receives the section object (e.g. { title, items })
instead of the actual row data item, causing it to resolve the wrong template.

Fix by adding _getItemTemplateInSection(section, index) to ListViewBase that
uses _getDataItemInSection and _getItemsInSection to correctly resolve the
data item and its section's items array before passing them to the selector.

On iOS, tableViewCellForRowAtIndexPath, tableViewHeightForRowAtIndexPath, and
_prepareCell are updated to call _getItemTemplateInSection when sectioned is
enabled. The broken absoluteIndex workaround in _prepareCell is removed.

On Android, getItemViewType and _createItemView are updated to call
_getItemTemplateInSection when sectioned is enabled.

Fixes NativeScript#11133
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 19, 2026

View your CI Pipeline Execution ↗ for commit 97ab92a

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 32s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-19 04:55:46 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sectioned ListView may return wrong template

1 participant