MCPcopy Index your code
hub / github.com/adobe/react-spectrum / CollectionRoot

Function CollectionRoot

packages/react-aria-components/src/Virtualizer.tsx:92–142  ·  view source on GitHub ↗
({
  collection,
  persistedKeys,
  scrollRef,
  renderDropIndicator
}: CollectionRootProps)

Source from the content-addressed store, hash-verified

90}
91
92function CollectionRoot({
93 collection,
94 persistedKeys,
95 scrollRef,
96 renderDropIndicator
97}: CollectionRootProps) {
98 let {layout, layoutOptions} = useContext(LayoutContext)!;
99 let layoutOptions2 = layout.useLayoutOptions?.();
100 let state = useVirtualizerState({
101 allowsWindowScrolling: true,
102 layout,
103 collection,
104 renderView: (type, item) => {
105 return item?.render?.(item);
106 },
107 onVisibleRectChange(rect) {
108 let element = scrollRef?.current;
109 if (element) {
110 element.scrollLeft = rect.x;
111 element.scrollTop = rect.y;
112 }
113 },
114 persistedKeys,
115 layoutOptions: useMemo(() => {
116 if (layoutOptions && layoutOptions2) {
117 return {...layoutOptions, ...layoutOptions2};
118 }
119 return layoutOptions || layoutOptions2;
120 }, [layoutOptions, layoutOptions2])
121 });
122
123 let {contentProps} = useScrollView(
124 {
125 onVisibleRectChange: state.setVisibleRect,
126 onSizeChange: state.setSize,
127 contentSize: state.contentSize,
128 onScrollStart: state.startScrolling,
129 onScrollEnd: state.endScrolling,
130 allowsWindowScrolling: true
131 },
132 scrollRef!
133 );
134
135 return (
136 <div {...contentProps}>
137 <VirtualizerContext.Provider value={state}>
138 {renderChildren(null, state.visibleViews, renderDropIndicator)}
139 </VirtualizerContext.Provider>
140 </div>
141 );
142}
143
144function CollectionBranch({parent, renderDropIndicator}: CollectionBranchProps) {
145 let virtualizer = useContext(VirtualizerContext);

Callers

nothing calls this directly

Calls 5

useVirtualizerStateFunction · 0.90
useScrollViewFunction · 0.90
renderChildrenFunction · 0.70
useLayoutOptionsMethod · 0.65
renderMethod · 0.45

Tested by

no test coverage detected