MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / _prepareCell

Method _prepareCell

packages/core/ui/list-view/index.ios.ts:790–852  ·  view source on GitHub ↗
(cell: ListViewCell, indexPath: NSIndexPath)

Source from the content-addressed store, hash-verified

788 }
789
790 public _prepareCell(cell: ListViewCell, indexPath: NSIndexPath): number {
791 let cellHeight: number;
792 try {
793 this._preparingCell = true;
794 let view: ItemView = cell.view;
795 if (!view) {
796 if (this.sectioned) {
797 // For sectioned data, we need to calculate the absolute index for template selection
798 let absoluteIndex = 0;
799 for (let i = 0; i < indexPath.section; i++) {
800 absoluteIndex += this._getItemsInSection(i).length;
801 }
802 absoluteIndex += indexPath.row;
803 view = this._getItemTemplate(absoluteIndex).createView();
804 } else {
805 view = this._getItemTemplate(indexPath.row).createView();
806 }
807 }
808
809 const args = notifyForItemAtIndex(this, cell, view, ITEMLOADING, indexPath);
810 view = args.view || this._getDefaultItemContent(this.sectioned ? indexPath.row : indexPath.row);
811
812 // Proxy containers should not get treated as layouts.
813 // Wrap them in a real layout as well.
814 if (view instanceof ProxyViewContainer) {
815 const sp = new StackLayout();
816 sp.addChild(view);
817 view = sp;
818 }
819
820 // If cell is reused it have old content - remove it first.
821 if (!cell.view) {
822 cell.owner = new WeakRef(view);
823 } else if (cell.view !== view) {
824 // Remove view from super view now as nativeViewProtected will be null afterwards
825 (<UIView>cell.view.nativeViewProtected)?.removeFromSuperview();
826 this._removeContainer(cell);
827 cell.owner = new WeakRef(view);
828 }
829
830 if (this.sectioned) {
831 this._prepareItemInSection(view, indexPath.section, indexPath.row);
832 view._listViewItemIndex = indexPath.row; // Keep row index for compatibility
833 (view as any)._listViewSectionIndex = indexPath.section;
834 } else {
835 this._prepareItem(view, indexPath.row);
836 view._listViewItemIndex = indexPath.row;
837 }
838 this._map.set(cell, view);
839
840 // We expect that views returned from itemLoading are new (e.g. not reused).
841 if (view && !view.parent) {
842 this._addView(view);
843 cell.contentView.addSubview(view.nativeViewProtected);
844 }
845
846 cellHeight = this._layoutCell(view, indexPath);
847 } finally {

Calls 6

_removeContainerMethod · 0.95
_layoutCellMethod · 0.95
notifyForItemAtIndexFunction · 0.85
addChildMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected