fix(listview): correct item template resolution in sectioned ListView#11184
Open
VeinDevTtv wants to merge 2 commits intoNativeScript:mainfrom
Open
fix(listview): correct item template resolution in sectioned ListView#11184VeinDevTtv wants to merge 2 commits intoNativeScript:mainfrom
VeinDevTtv wants to merge 2 commits intoNativeScript:mainfrom
Conversation
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
|
View your CI Pipeline Execution ↗ for commit 97ab92a
☁️ Nx Cloud last updated this comment at |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
When using a sectioned
ListViewwith multiple item templates and anitemTemplateSelector, the wrong template is returned for items._getItemTemplate(index)calls_getDataItem(index)which reads directly fromthis.items[index]. In sectioned mode,this.itemsis 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. TheitemTemplateSelectorthen receives the wrong data and resolves the wrong template key, causing incorrect cell types to be recycled and rendered.On iOS,
_prepareCellcontained a brokenabsoluteIndexworkaround that summed up items across sections and fed that offset back into the same flat_getItemTemplate— which still hitsthis.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 toListViewBase. It uses_getDataItemInSectionto correctly fetch the row item from within its section, and_getItemsInSectionto pass the section's own items array to theitemTemplateSelector— matching the same contract that_prepareItemInSectionuses for binding contexts.All call sites that select a template for a sectioned row are updated to use this method:
tableViewCellForRowAtIndexPath,tableViewHeightForRowAtIndexPath, and_prepareCell(replacing the broken absoluteIndex workaround).getItemViewTypeand_createItemView.Fixes #11133.