@@ -39,6 +39,7 @@ const itemsGrid = Array.from({ length: 300 }).map((_, iy) => Array.from({ length
3939function ListWithHookExample() {
4040 const items = itemsLine;
4141 const containerRef = (0, react_1.useRef)(undefined);
42+ const infoRef = (0, react_1.useRef)(undefined);
4243 const itemHeight = 40;
4344 const { renderedItems, updateViewRect } = (0, __1.useVirtualOverflowY)({
4445 containerRef,
@@ -49,9 +50,14 @@ function ListWithHookExample() {
4950 renderItem: (itemIndex, offsetTop, item = items[itemIndex]) => ((0, jsx_runtime_1.jsx)("div", { style: { position: 'absolute', top: `${offsetTop}px` }, children: (0, jsx_runtime_1.jsx)("div", { style: { height: '40px' }, children: item }) }, item)),
5051 });
5152 (0, react_1.useEffect)(() => {
52- setInterval(() => updateViewRect(), 8);
53+ // in case of animated containers
54+ // setInterval(() => updateViewRect(), 8);
55+ setInterval(() => {
56+ const visibleRect = (0, __1.virtualOverflowCalcVisibleRect)(containerRef.current);
57+ infoRef.current.innerText = `Visible rect of content:\n\n${JSON.stringify(visibleRect, null, 2)}`;
58+ }, 24);
5359 }, []);
54- return ((0, jsx_runtime_1.jsx)("div", { style: { overflowY: 'scroll', height: '300px', background: 'lightgreen' }, children: (0, jsx_runtime_1.jsx)("div", { ref: containerRef, style: { position: 'relative', height: `${itemHeight * items.length}px` }, children: renderedItems }) }));
60+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1. jsx)("div", { ref: infoRef, style: { position: 'fixed', top: 0, right: 0, paddingRight: '40px', width: '200px' } }), (0, jsx_runtime_1.jsx)("div", { style: { overflowY: 'scroll', height: '300px', background: 'lightgreen' }, children: (0, jsx_runtime_1.jsx)("div", { ref: containerRef, style: { position: 'relative', height: `${itemHeight * items.length}px` }, children: renderedItems }) })] }));
5561}
5662function VerticalListExample() {
5763 const items = itemsLine;
@@ -68,7 +74,7 @@ function App() {
6874 }, children: "Scroll me down" }), (0, jsx_runtime_1.jsxs)("div", { style: { overflowY: 'scroll', height: '600px', background: 'blue' }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
6975 height: '700px', fontSize: '60px',
7076 color: 'white'
71- }, children: "Scroll me down" }), (0, jsx_runtime_1.jsx)(VerticalListExample , {})] }), (0, jsx_runtime_1.jsx)("div", { style: { height: '700px' } })] }));
77+ }, children: "Scroll me down" }), (0, jsx_runtime_1.jsx)(ListWithHookExample , {})] }), (0, jsx_runtime_1.jsx)("div", { style: { height: '700px' } })] }));
7278}
7379const rootElement = document.getElementById("demo");
7480const root = client_1.default.createRoot(rootElement);
0 commit comments