MCPcopy Create free account
hub / github.com/adobe/react-spectrum / CollectionRoot

Function CollectionRoot

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

Source from the content-addressed store, hash-verified

97}
98
99function CollectionRoot({
100 collection,
101 persistedKeys,
102 scrollRef,
103 renderDropIndicator
104}: CollectionRootProps) {
105 let {layout, layoutOptions, shouldObserveItemSize} = useContext(VirtualizerOptionsContext)!;
106 // oxlint-disable-next-line react/react-compiler
107 let layoutOptions2 = layout.useLayoutOptions?.();
108 let state = useVirtualizerState({
109 allowsWindowScrolling: true,
110 layout,
111 collection,
112 renderView: (type, item) => {
113 return item?.render?.(item);
114 },
115 onVisibleRectChange(rect) {
116 let element = scrollRef?.current;
117 if (element) {
118 // oxlint-disable-next-line react/react-compiler
119 element.scrollLeft = rect.x;
120 element.scrollTop = rect.y;
121 }
122 },
123 persistedKeys,
124 layoutOptions: useMemo(
125 () =>
126 layoutOptions && layoutOptions2
127 ? {...layoutOptions, ...layoutOptions2}
128 : layoutOptions || layoutOptions2,
129 [layoutOptions, layoutOptions2]
130 )
131 });
132
133 let {contentProps} = useScrollView(
134 {
135 onVisibleRectChange: state.setVisibleRect,
136 onSizeChange: state.setSize,
137 contentSize: state.contentSize,
138 onScrollStart: state.startScrolling,
139 onScrollEnd: state.endScrolling,
140 allowsWindowScrolling: true
141 },
142 scrollRef!
143 );
144
145 return (
146 <div {...contentProps}>
147 <VirtualizerContext.Provider value={state}>
148 {renderChildren(null, state.visibleViews, renderDropIndicator, shouldObserveItemSize)}
149 </VirtualizerContext.Provider>
150 </div>
151 );
152}
153
154function CollectionBranch({parent, renderDropIndicator}: CollectionBranchProps) {
155 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