mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
watch bounds when shifting content
This commit is contained in:
parent
efbd714fa5
commit
462ff37ff3
@ -35,9 +35,18 @@ export function VirtualList({ topics }) {
|
|||||||
setItems((m) => { m.delete(id); return new Map(m); })
|
setItems((m) => { m.delete(id); return new Map(m); })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const growCanvasHeight = (val) => {
|
||||||
|
setCanvasHeight((h) => {
|
||||||
|
if (val > h) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewHeight * 3 > canvasHeight) {
|
if (viewHeight * 3 > canvasHeight) {
|
||||||
setCanvasHeight(viewHeight*3);
|
growCanvasHeight(viewHeight*3);
|
||||||
}
|
}
|
||||||
setTopics();
|
setTopics();
|
||||||
}, [viewHeight]);
|
}, [viewHeight]);
|
||||||
@ -147,6 +156,11 @@ export function VirtualList({ topics }) {
|
|||||||
}
|
}
|
||||||
scrollTop.current += shift;
|
scrollTop.current += shift;
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
||||||
|
|
||||||
|
let view = getPlacement();
|
||||||
|
if (view.position.bottom + REDZONE > canvasHeight) {
|
||||||
|
growCanvasHeight(view.position.bottom + REDZONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -159,14 +173,20 @@ export function VirtualList({ topics }) {
|
|||||||
pos += containers.current[i].height + 2 * GUTTER;
|
pos += containers.current[i].height + 2 * GUTTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos + viewHeight + REDZONE > canvasHeight) {
|
if (pos + REDZONE > canvasHeight) {
|
||||||
let shift = canvasHeight / 2;
|
let shift = canvasHeight / 2;
|
||||||
for (let i = 0; i < containers.current.length; i++) {
|
let view = getPlacement();
|
||||||
containers.current[i].top -= shift;
|
if (view.position.top < shift + REDZONE) {
|
||||||
updateItem(containers.current[i].id, getItem(containers.current[i]));
|
growCanvasHeight(view.position.bottom + REDZONE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (let i = 0; i < containers.current.length; i++) {
|
||||||
|
containers.current[i].top -= shift;
|
||||||
|
updateItem(containers.current[i].id, getItem(containers.current[i]));
|
||||||
|
}
|
||||||
|
scrollTop.current -= shift;
|
||||||
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
||||||
}
|
}
|
||||||
scrollTop.current -= shift;
|
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user