mirror of
https://github.com/balzack/databag.git
synced 2025-03-13 00:50:03 +00:00
fix empty list in safari bug
This commit is contained in:
parent
226b95ddb4
commit
b39f24d9a7
@ -21,10 +21,10 @@ export const ImageAssetWrapper = styled.div`
|
|||||||
}
|
}
|
||||||
|
|
||||||
.expand {
|
.expand {
|
||||||
padding-right: 2px;
|
padding-left: 4px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
right: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ export const TopicItemWrapper = styled.div`
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
padding-right: 8px;
|
|
||||||
|
|
||||||
.avatar {
|
.avatar {
|
||||||
height: 32px;
|
height: 32px;
|
||||||
@ -43,6 +42,7 @@ export const TopicItemWrapper = styled.div`
|
|||||||
|
|
||||||
.message {
|
.message {
|
||||||
padding-top: 6px;
|
padding-top: 6px;
|
||||||
|
padding-right: 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
@ -39,11 +39,11 @@ export const VideoAssetWrapper = styled.div`
|
|||||||
}
|
}
|
||||||
|
|
||||||
.expand {
|
.expand {
|
||||||
padding-right: 2px;
|
padding-left: 4px;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
right: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
const DEFAULT_LIST_HEIGHT = 4096;
|
const DEFAULT_LIST_HEIGHT = 4096;
|
||||||
const GUTTER = 6;
|
const GUTTER = 6;
|
||||||
|
|
||||||
const [ viewHeight, setViewHeight ] = useState(DEFAULT_LIST_HEIGHT);
|
|
||||||
const [ canvasHeight, setCanvasHeight ] = useState(DEFAULT_LIST_HEIGHT*3);
|
const [ canvasHeight, setCanvasHeight ] = useState(DEFAULT_LIST_HEIGHT*3);
|
||||||
const [ slots, setSlots ] = useState(new Map());
|
const [ slots, setSlots ] = useState(new Map());
|
||||||
const [ scroll, setScroll ] = useState('hidden');
|
const [ scroll, setScroll ] = useState('hidden');
|
||||||
|
|
||||||
let update = useRef(0);
|
let update = useRef(0);
|
||||||
|
let viewHeight = useRef(DEFAULT_LIST_HEIGHT);
|
||||||
let latch = useRef(true);
|
let latch = useRef(true);
|
||||||
let scrollTop = useRef(0);
|
let scrollTop = useRef(0);
|
||||||
let containers = useRef([]);
|
let containers = useRef([]);
|
||||||
@ -49,11 +49,8 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewHeight * 3 > canvasHeight) {
|
|
||||||
growCanvasHeight(viewHeight * 3);
|
|
||||||
}
|
|
||||||
updateCanvas();
|
updateCanvas();
|
||||||
}, [viewHeight]);
|
}, [canvasHeight]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (key.current != id) {
|
if (key.current != id) {
|
||||||
@ -65,10 +62,6 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
setItems();
|
setItems();
|
||||||
}, [items, id]);
|
}, [items, id]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
updateCanvas();
|
|
||||||
}, [viewHeight, canvasHeight]);
|
|
||||||
|
|
||||||
const onScrollWheel = (e) => {
|
const onScrollWheel = (e) => {
|
||||||
if (e.deltaY < 0 && latch.current) {
|
if (e.deltaY < 0 && latch.current) {
|
||||||
latch.current = false;
|
latch.current = false;
|
||||||
@ -96,15 +89,15 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
let view = getPlacement();
|
let view = getPlacement();
|
||||||
if (view && containers.current[containers.current.length - 1].index == items.length - 1) {
|
if (view && containers.current[containers.current.length - 1].index == items.length - 1) {
|
||||||
if (view?.overscan?.bottom <= 0) {
|
if (view?.overscan?.bottom <= 0) {
|
||||||
if (view.position.height < viewHeight) {
|
if (view.position.height < viewHeight.current) {
|
||||||
if (scrollTop.current != view.position.top) {
|
if (scrollTop.current != view.position.top) {
|
||||||
scrollTop.current = view.position.top;
|
scrollTop.current = view.position.top;
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (scrollTop.current != view.position.bottom - viewHeight) {
|
if (scrollTop.current != view.position.bottom - viewHeight.current) {
|
||||||
scrollTop.current = view.position.bottom - viewHeight;
|
scrollTop.current = view.position.bottom - viewHeight.current;
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,7 +155,7 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
containers.current.shift();
|
containers.current.shift();
|
||||||
}
|
}
|
||||||
while (containers.current.length > 0 &&
|
while (containers.current.length > 0 &&
|
||||||
containers.current[containers.current.length - 1].top > scrollTop.current + viewHeight + HOLDZONE) {
|
containers.current[containers.current.length - 1].top > scrollTop.current + viewHeight.current + HOLDZONE) {
|
||||||
removeSlot(containers.current[containers.current.length - 1].id);
|
removeSlot(containers.current[containers.current.length - 1].id);
|
||||||
containers.current.pop();
|
containers.current.pop();
|
||||||
}
|
}
|
||||||
@ -226,15 +219,15 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
if (latch.current) {
|
if (latch.current) {
|
||||||
let view = getPlacement();
|
let view = getPlacement();
|
||||||
if (view) {
|
if (view) {
|
||||||
if (view.position.height < viewHeight) {
|
if (view.position.height < viewHeight.current) {
|
||||||
if (scrollTop.current != view.position.top) {
|
if (scrollTop.current != view.position.top) {
|
||||||
scrollTop.current = view.position.top;
|
scrollTop.current = view.position.top;
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0, behavior: 'smooth' });
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (scrollTop.current != view.position.bottom - viewHeight) {
|
if (scrollTop.current != view.position.bottom - viewHeight.current) {
|
||||||
scrollTop.current = view.position.bottom - viewHeight;
|
scrollTop.current = view.position.bottom - viewHeight.current;
|
||||||
listRef.current.scrollTo({ top: scrollTop.current, left: 0, behavior: 'smooth' });
|
listRef.current.scrollTo({ top: scrollTop.current, left: 0, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +303,7 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
let top = containers.current[0].top;
|
let top = containers.current[0].top;
|
||||||
let bottom = containers.current[containers.current.length-1].top + containers.current[containers.current.length-1].height + 2 * GUTTER;
|
let bottom = containers.current[containers.current.length-1].top + containers.current[containers.current.length-1].height + 2 * GUTTER;
|
||||||
let overTop = scrollTop.current - top;
|
let overTop = scrollTop.current - top;
|
||||||
let overBottom = bottom - (scrollTop.current + viewHeight);
|
let overBottom = bottom - (scrollTop.current + viewHeight.current);
|
||||||
return {
|
return {
|
||||||
position: { top, bottom, height: bottom - top },
|
position: { top, bottom, height: bottom - top },
|
||||||
overscan: { top: overTop, bottom: overBottom }
|
overscan: { top: overTop, bottom: overBottom }
|
||||||
@ -320,7 +313,10 @@ export function VirtualList({ id, items, itemRenderer }) {
|
|||||||
return (
|
return (
|
||||||
<ReactResizeDetector handleHeight={true}>
|
<ReactResizeDetector handleHeight={true}>
|
||||||
{({ height }) => {
|
{({ height }) => {
|
||||||
setViewHeight(height);
|
if (height) {
|
||||||
|
growCanvasHeight(height * 3);
|
||||||
|
viewHeight.current = height;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<VirtualListWrapper onScroll={onScrollView} onWheel={onScrollWheel}>
|
<VirtualListWrapper onScroll={onScrollView} onWheel={onScrollWheel}>
|
||||||
<div class="rollview" style={{ overflowY: 'auto' }} ref={listRef} onScroll={onScrollView}>
|
<div class="rollview" style={{ overflowY: 'auto' }} ref={listRef} onScroll={onScrollView}>
|
||||||
|
Loading…
Reference in New Issue
Block a user