Browse Source

Rewrote debouncing of onResize (#11899)

* Rewrote debouncing of onResize 

Fixes https://github.com/vaadin/framework/issues/11892

* Fixing typo in variable name
tags/8.11.0.alpha1
Tatu Lund 4 years ago
parent
commit
3df3420f9e
No account linked to committer's email address
1 changed files with 33 additions and 15 deletions
  1. 33
    15
      client/src/main/java/com/vaadin/client/widgets/Grid.java

+ 33
- 15
client/src/main/java/com/vaadin/client/widgets/Grid.java View File

@@ -4366,6 +4366,9 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,

private boolean refreshBodyRequested = false;

private boolean resizeRequested = false;
private boolean resizeRefreshScheduled = false;

private DragAndDropHandler.DragAndDropCallback headerCellDndCallback = new DragAndDropCallback() {

private final AutoScrollerCallback autoScrollerCallback = new AutoScrollerCallback() {
@@ -9264,23 +9267,38 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>,
/*
* Delay calculation to be deferred so Escalator can do it's magic.
*/
Scheduler.get().scheduleFinally(() -> {
if (escalator
.getInnerWidth() != autoColumnWidthsRecalculator.lastCalculatedInnerWidth) {
recalculateColumnWidths();
}
resizeRequested = true;
if (!resizeRefreshScheduled) {
resizeRefreshScheduled = true;
Scheduler.get().scheduleFixedDelay(() -> {
if (!resizeRequested) {
doRefreshOnResize();
resizeRefreshScheduled = 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() {

Loading…
Cancel
Save