Skip to content

Commit f6a5cde

Browse files
committed
perf: only recompute draggable position on window scroll
1 parent c5ef775 commit f6a5cde

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/droppable.directive.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,21 @@ export class DroppableDirective implements OnInit, OnDestroy {
7777
ngOnInit(): void {
7878
this.currentDragSubscription = this.draggableHelper.currentDrag.subscribe(
7979
drag$ => {
80+
let droppableRectangle = this.element.nativeElement.getBoundingClientRect();
81+
82+
/* istanbul ignore next */
83+
this.renderer.listen('window', 'scroll', () => {
84+
droppableRectangle = this.element.nativeElement.getBoundingClientRect();
85+
});
86+
8087
let currentDragDropData: any;
8188
const overlaps$ = drag$.pipe(
8289
map(({ clientX, clientY, dropData }) => {
8390
currentDragDropData = dropData;
8491
return isCoordinateWithinRectangle(
8592
clientX,
8693
clientY,
87-
this.element.nativeElement.getBoundingClientRect()
94+
droppableRectangle
8895
);
8996
})
9097
);

0 commit comments

Comments
 (0)