Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-poems-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-movable": patch
---

Use setState callback in finishDrop to avoid occasional flicker
48 changes: 25 additions & 23 deletions src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,31 +484,33 @@ class List<Value = string> extends React.Component<IProps<Value>> {
? -1
: Math.max(this.afterIndex, 0)
: oldIndex;
if (removeItem || hasChanged) {
this.props.onChange({
oldIndex,
newIndex,
targetRect: this.ghostRef.current!.getBoundingClientRect(),
});
}
this.props.afterDrag &&
this.props.afterDrag({
elements: this.getChildren(),
oldIndex,
newIndex,
const targetRect = this.ghostRef.current!.getBoundingClientRect();
this.setState({ itemDragged: -1, scrollingSpeed: 0 }, () => {
if (removeItem || hasChanged) {
this.props.onChange({
oldIndex,
newIndex,
targetRect: targetRect,
});
}
this.props.afterDrag &&
this.props.afterDrag({
elements: this.getChildren(),
oldIndex,
newIndex,
});
this.getChildren().forEach((item) => {
setItemTransition(item, 0);
transformItem(item, null);
(item as HTMLElement).style.touchAction = "";
});
this.getChildren().forEach((item) => {
setItemTransition(item, 0);
transformItem(item, null);
(item as HTMLElement).style.touchAction = "";
this.afterIndex = -2;
// sometimes the scroll gets messed up after the drop, fix:
if (this.lastScroll > 0) {
this.listRef.current!.scrollTop = this.lastScroll;
this.lastScroll = 0;
}
});
this.setState({ itemDragged: -1, scrollingSpeed: 0 });
this.afterIndex = -2;
// sometimes the scroll gets messed up after the drop, fix:
if (this.lastScroll > 0) {
this.listRef.current!.scrollTop = this.lastScroll;
this.lastScroll = 0;
}
};

onKeyDown = (e: React.KeyboardEvent) => {
Expand Down