伙计们,我已经尝试了几天了,但是我一直没能弄明白。我可以让这两个库单独工作,但是当我把两个库组合在一起时,我被困在为什么它不能工作。我想我不知何故把它们连接错了,我就是搞不清楚是什么。请帮帮忙。
Here is a CodeSandBox of my issue。
最后,这里是CodeSandBox中重要部分的代码片段:
getRowRender({ index, style }) {
const item = this.state.items[index];
return (
<Draggable draggableId={item.id} index={index} key={item.id}>
{(provided, snapshot) => (
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={getItemStyle(
snapshot.isDragging,
provided.draggableProps.style
)}
>
{item.content}
</div>
)}
</Draggable>
);
}
render() {
if (this.state.items) {
return (
<DragDropContext onDragEnd={this.onDragEnd}>
<Droppable
droppableId="droppable"
mode="virtual"
renderClone={(provided, snapshot, rubric) => (
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={getItemStyle(
snapshot.isDragging,
provided.draggableProps.style
)}
>
{this.state.items[rubric.source.index].content}
</div>
)}
>
{(provided, snapshot) => (
<AutoSizer>
{({ height, width }) => (
<List
{...provided.droppableProps}
height={height}
rowCount={this.state.items.length}
rowHeight={500}
width={width}
ref={(ref) => {
// react-virtualized has no way to get the list's ref that I can so
// So we use the `ReactDOM.findDOMNode(ref)` escape hatch to get the ref
if (ref) {
// eslint-disable-next-line react/no-find-dom-node
const whatHasMyLifeComeTo = ReactDOM.findDOMNode(ref);
if (whatHasMyLifeComeTo instanceof HTMLElement) {
provided.innerRef(whatHasMyLifeComeTo);
}
}
}}
style={getListStyle(snapshot.isDraggingOver)}
rowRenderer={this.getRowRender}
/>
)}
</AutoSizer>
)}
</Droppable>
</DragDropContext>
);
} else {
return null;
}
}发布于 2021-03-17 02:09:00
我想我已经解决了这个问题。
https://codesandbox.io/s/vertical-list-forked-risye
您没有将rowRenderer中的样式属性传递给virtualize,以正确的方式处理您的行。
此外,您的Autosizer没有增长超过高度:0,因为它的父级没有任何样式。
https://stackoverflow.com/questions/66329580
复制相似问题