// SectionList, a pure forwarder over VirtualizedSectionList, mirroring RN's layering // A content query does not resolve across a second `` hop, so the app's templates are // captured here and re-stamped onto the inner list import { ChangeDetectionStrategy, Component, ContentChild, ElementRef, Input, ViewChild, inject, } from '@angular/core'; import type { IInnerViewRef, IScrollViewHandle, IVirtualizedSectionListHandle, } from '@symbiote-native/components'; import { type IStyleProp, type ISymbioteEvent, type ISymbioteNode, type IViewStyle, } from '@symbiote-native/engine'; import { VListCellDirective, VListEmptyDirective, VListFooterDirective, VListHeaderDirective, VListSeparatorDirective, } from '../virtualized-list'; import { VListOutletDirective } from '../virtualized-list/directives'; import { LIST_ACCESSIBILITY_FORWARD } from '../virtualized-list/list-a11y-forward'; import { ListEventsBase } from '../virtualized-list/list-events'; import { provideGateDemand } from '../../gate-demand'; import { stableAnchorStyle, SymbioteStyleInputDirective, } from '../../primitives'; import { VSectionFooterDirective, VSectionHeaderDirective, VSectionItemDirective, VSectionSeparatorDirective, VirtualizedSectionList, type ISection, type IVirtualizedSectionListProps, } from '../virtualized-section-list'; export type { ISection } from '../virtualized-section-list'; export type ISectionListHandle = IVirtualizedSectionListHandle; // Re-exported so app code gets the whole `vSection*` and `vList*` authoring surface from here export { VSectionFooterDirective, VSectionHeaderDirective, VSectionItemDirective, VSectionSeparatorDirective, } from '../virtualized-section-list'; export { VListEmptyDirective, VListFooterDirective, VListHeaderDirective, VListSeparatorDirective, } from '../virtualized-list'; // RN layers the two one-for-one, so the prop type is shared verbatim export type ISectionListProps = IVirtualizedSectionListProps; // The plain inputs: the full surface minus the events exposed as real outputs export type ISectionListInputs = Omit< ISectionListProps, | 'onEndReached' | 'onStartReached' | 'onRefresh' | 'onAccessibilityAction' | 'onAccessibilityTap' | 'onMagicTap' | 'onAccessibilityEscape' >; @Component({ selector: 'SectionList', standalone: true, viewProviders: [provideGateDemand(() => SectionList)], hostDirectives: [ { directive: SymbioteStyleInputDirective, inputs: ['style'] }, ], imports: [ VirtualizedSectionList, VSectionItemDirective, VSectionHeaderDirective, VSectionFooterDirective, VSectionSeparatorDirective, VListHeaderDirective, VListFooterDirective, VListEmptyDirective, VListSeparatorDirective, VListOutletDirective, ], changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (sectionHeaderDir !== undefined) { } @if (sectionFooterDir !== undefined) { } @if (sectionSeparatorDir !== undefined) { } @if (listHeaderDir !== undefined) { } @if (listFooterDir !== undefined) { } @if (listEmptyDir !== undefined) { } @if (itemSeparatorDir !== undefined) { } `, }) export class SectionList extends ListEventsBase implements ISectionListInputs, IVirtualizedSectionListHandle { @Input({ required: true }) sections!: ReadonlyArray>; @Input() keyExtractor?: (item: ItemT, index: number) => string; // Passed through flat, `VirtualizedSectionList` owns the sections-versus-entries wrapper @Input() getItemLayout?: ( data: ReadonlyArray> | null, index: number, ) => { length: number; offset: number; index: number }; @Input() stickySectionHeadersEnabled?: boolean; @Input() extraData?: unknown; @Input() onEndReachedThreshold?: number; @Input() onStartReachedThreshold?: number; @Input() refreshing?: boolean | null; @Input() progressViewOffset?: number; @Input() initialNumToRender?: number; @Input() initialScrollIndex?: number; @Input() maxToRenderPerBatch?: number; @Input() updateCellsBatchingPeriod?: number; @Input() windowSize?: number; @Input() disableVirtualization?: boolean; @Input() inverted?: boolean; @Input() horizontal?: boolean; @Input() maintainVisibleContentPosition?: { minIndexForVisible: number; autoscrollToTopThreshold?: number; }; @Input() onScroll?: (event: ISymbioteEvent) => void; @Input() onScrollBeginDrag?: (event: ISymbioteEvent) => void; @Input() onScrollEndDrag?: (event: ISymbioteEvent) => void; @Input() onMomentumScrollBegin?: (event: ISymbioteEvent) => void; @Input() onMomentumScrollEnd?: (event: ISymbioteEvent) => void; @Input() onContentSizeChange?: (width: number, height: number) => void; @Input() scrollEventThrottle?: number; @Input() keyboardShouldPersistTaps?: boolean | 'always' | 'never' | 'handled'; @Input() keyboardDismissMode?: 'none' | 'on-drag' | 'interactive'; @Input() removeClippedSubviews?: boolean; @Input() nestedScrollEnabled?: boolean; @Input() stickyHeaderHiddenOnScroll?: boolean; @Input() innerViewRef?: IInnerViewRef; @Input() style?: IStyleProp; @Input() contentContainerStyle?: IStyleProp; @Input() listHeaderComponentStyle?: IStyleProp; @Input() listFooterComponentStyle?: IStyleProp; @Input() testID?: string; @Input() nativeID?: string; // A flat object bound to `[style]`, merged with this host's own class-derived style. A fresh // object per read would defeat the inner list's dedup gate, `stableAnchorStyle` keeps it steady private cachedResolvedStyle: Record | undefined; get resolvedStyle(): IViewStyle { this.cachedResolvedStyle = stableAnchorStyle( this.elementRef, this.style, this.cachedResolvedStyle, ); return this.cachedResolvedStyle; } // The app's templates, captured from directly projected content and re-stamped above @ContentChild(VSectionItemDirective) sectionItemDir?: VSectionItemDirective; @ContentChild(VSectionHeaderDirective) sectionHeaderDir?: VSectionHeaderDirective; @ContentChild(VSectionFooterDirective) sectionFooterDir?: VSectionFooterDirective; @ContentChild(VSectionSeparatorDirective) sectionSeparatorDir?: VSectionSeparatorDirective; @ContentChild(VListHeaderDirective) listHeaderDir?: VListHeaderDirective; @ContentChild(VListFooterDirective) listFooterDir?: VListFooterDirective; @ContentChild(VListEmptyDirective) listEmptyDir?: VListEmptyDirective; @ContentChild(VListSeparatorDirective) itemSeparatorDir?: VListSeparatorDirective; @ContentChild(VListCellDirective) cellDir?: VListCellDirective; // The inner list, whose instance is the scroll handle, reads lazily @ViewChild(VirtualizedSectionList) private list?: VirtualizedSectionList; // This component's own host, the anchor `class="..."` resolves onto, not the inner list's private readonly elementRef = inject(ElementRef); scrollToLocation(params: { sectionIndex: number; itemIndex: number; viewOffset?: number; viewPosition?: number; animated?: boolean; }): void { this.list?.scrollToLocation(params); } flashScrollIndicators(): void { this.list?.flashScrollIndicators(); } getNativeScrollRef(): ISymbioteNode | null { return this.list?.getNativeScrollRef() ?? null; } getScrollableNode(): IScrollViewHandle | null { return this.list?.getScrollableNode() ?? null; } getScrollResponder(): IScrollViewHandle | null { return this.list?.getScrollResponder() ?? null; } getScrollNode(): ISymbioteNode | null { return this.list?.getScrollNode() ?? null; } getScrollRef(): ISymbioteNode | null { return this.list?.getScrollRef() ?? null; } recordInteraction(): void { this.list?.recordInteraction(); } setNativeProps(props: Record): void { this.list?.setNativeProps(props); } }