MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / _prepareHeader

Method _prepareHeader

packages/core/ui/list-view/index.ios.ts:870–949  ·  view source on GitHub ↗
(headerCell: ListViewHeaderCell, section: number)

Source from the content-addressed store, hash-verified

868 }
869
870 public _prepareHeader(headerCell: ListViewHeaderCell, section: number): number {
871 let headerHeight: number;
872 try {
873 this._preparingHeader = true;
874 let view: View = headerCell.view;
875 if (!view) {
876 view = this._getHeaderTemplate();
877 if (!view) {
878 if (Trace.isEnabled()) {
879 Trace.write(`ListView: Failed to create header view for section ${section}`, Trace.categories.Debug);
880 }
881 // Create a fallback view
882 const lbl = new Label();
883 lbl.text = `Section ${section}`;
884 view = lbl;
885 }
886 }
887
888 // Handle header cell reuse
889 if (!headerCell.view) {
890 headerCell.owner = new WeakRef(view);
891 } else if (headerCell.view !== view) {
892 // Remove old view and set new one
893 (<UIView>headerCell.view.nativeViewProtected)?.removeFromSuperview();
894 this._removeHeaderContainer(headerCell);
895 headerCell.owner = new WeakRef(view);
896 }
897
898 // Clear existing binding context and set new one
899 if (view.bindingContext) {
900 view.bindingContext = null;
901 }
902
903 if (this.sectioned) {
904 const sectionData = this._getSectionData(section);
905 if (sectionData) {
906 view.bindingContext = sectionData;
907 } else {
908 // Fallback if section data is missing
909 view.bindingContext = { title: `Section ${section}`, section: section };
910 }
911 } else {
912 view.bindingContext = this.bindingContext;
913 }
914
915 // Force immediate binding context evaluation
916 if (view && typeof (view as any)._onBindingContextChanged === 'function') {
917 (view as any)._onBindingContextChanged(null, view.bindingContext);
918
919 // Also trigger for child views
920 // @ts-ignore
921 if (view._childrenCount) {
922 view.eachChildView((child) => {
923 if (typeof (child as any)._onBindingContextChanged === 'function') {
924 (child as any)._onBindingContextChanged(null, view.bindingContext);
925 }
926 return true;
927 });

Calls 8

_getHeaderTemplateMethod · 0.95
_layoutHeaderMethod · 0.95
isEnabledMethod · 0.80
writeMethod · 0.65
eachChildViewMethod · 0.45
setMethod · 0.45
requestLayoutMethod · 0.45

Tested by

no test coverage detected