FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(listview): correct item template resolution in sectioned ListView by VeinDevTtv · Pull Request #11184 · NativeScript/NativeScript · GitHub

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

Merged
NathanWalker merged 5 commits into
NativeScript:mainfrom
VeinDevTtv:fix/sectioned-listview-item-template-selector
Aug 14, 2026
Merged

fix(listview): correct item template resolution in sectioned ListView#11184
NathanWalker merged 5 commits into
NativeScript:mainfrom
VeinDevTtv:fix/sectioned-listview-item-template-selector

Conversation

VeinDevTtv commented Apr 19, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

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 Bot commented Apr 19, 2026
edited
Loading

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit f39a385

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

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-08-14 22:10:40 UTC

Copy link
Copy Markdown
Contributor

Thank you for this @VeinDevTtv! Did you confirm this with the toolbox as well? npm start > toolboxios ENTER ... or toolboxandroid - navigate to the demo page for list-page-sticky.

NathanWalker added this to the 9.1 milestone May 16, 2026
NathanWalker merged commit 17ab715 into NativeScript:main Aug 14, 2026
2 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

2 participants


Back | FazBrowse Home | New Git URL