Skip to content

Commit

Permalink
Rewrote debouncing of onResize
Browse files Browse the repository at this point in the history
Fixes #11892
  • Loading branch information
TatuLund committed Feb 24, 2020
1 parent 684c23a commit 7ddbe5b
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions client/src/main/java/com/vaadin/client/widgets/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -4366,6 +4366,9 @@ private void removeColumnHidingToggle(Column<?, T> column) {

private boolean refreshBodyRequested = false;

private boolean resizeRequested = false;
private boolean resizeRerfreshScheduled = false;

private DragAndDropHandler.DragAndDropCallback headerCellDndCallback = new DragAndDropCallback() {

private final AutoScrollerCallback autoScrollerCallback = new AutoScrollerCallback() {
Expand Down Expand Up @@ -9264,23 +9267,38 @@ public void onResize() {
/*
* Delay calculation to be deferred so Escalator can do it's magic.
*/
Scheduler.get().scheduleFinally(() -> {
if (escalator
.getInnerWidth() != autoColumnWidthsRecalculator.lastCalculatedInnerWidth) {
recalculateColumnWidths();
}
resizeRequested = true;
if (!resizeRerfreshScheduled) {
resizeRerfreshScheduled = true;
Scheduler.get().scheduleFixedDelay(() -> {
if (!resizeRequested) {
doRefreshOnResize();
resizeRerfreshScheduled = false;
return false;
} else {
resizeRequested = false;
return true;
}
}, 50);
}
}

private void doRefreshOnResize() {
if (escalator
.getInnerWidth() != autoColumnWidthsRecalculator.lastCalculatedInnerWidth) {
recalculateColumnWidths();
}

// Vertical resizing could make editor positioning invalid so it
// needs to be recalculated on resize
if (isEditorActive()) {
editor.updateVerticalScrollPosition();
}
// Vertical resizing could make editor positioning invalid so it
// needs to be recalculated on resize
if (isEditorActive()) {
editor.updateVerticalScrollPosition();
}

// if there is a resize, we need to refresh the body to avoid an
// off-by-one error which occurs when the user scrolls all the
// way to the bottom.
refreshBody();
});
// if there is a resize, we need to refresh the body to avoid an
// off-by-one error which occurs when the user scrolls all the
// way to the bottom.
refreshBody();
}

private double getEscalatorInnerHeight() {
Expand Down

0 comments on commit 7ddbe5b

Please sign in to comment.