Skip to content

Commit

Permalink
BaseScrollContainer: fix missing ScrollEvent.SCROLL when automaticall…
Browse files Browse the repository at this point in the history
…y restricting current scroll position to min or max
  • Loading branch information
joshtynjala committed Oct 9, 2023
1 parent f0226e8 commit c793f88
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/feathers/controls/supportClasses/BaseScrollContainer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,15 +1232,22 @@ class BaseScrollContainer extends FeathersControl implements IFocusObject {
}
// by checking for the minimum or maximum changing, ensures that
// scrollX/Y can be set out of range on purpose
if (this._prevMinScrollX != this.scroller.minScrollX && this.scroller.scrollX < this.scroller.minScrollX) {
this.scroller.restrictedScrollX = this.scroller.scrollX;
} else if (this._prevMaxScrollX != this.scroller.maxScrollX && this.scroller.scrollX > this.scroller.maxScrollX) {
this.scroller.restrictedScrollX = this.scroller.scrollX;
}
if (this._prevMinScrollY != this.scroller.minScrollY && this.scroller.scrollY < this.scroller.minScrollY) {
this.scroller.restrictedScrollY = this.scroller.scrollY;
} else if (this._prevMaxScrollY != this.scroller.maxScrollY && this.scroller.scrollY > this.scroller.maxScrollY) {
this.scroller.restrictedScrollY = this.scroller.scrollY;
var currentScrollX = this.scroller.scrollX;
var currentScrollY = this.scroller.scrollY;
if (this._prevMinScrollX != this.scroller.minScrollX && currentScrollX < this.scroller.minScrollX) {
this.scroller.restrictedScrollX = currentScrollX;
} else if (this._prevMaxScrollX != this.scroller.maxScrollX && currentScrollX > this.scroller.maxScrollX) {
this.scroller.restrictedScrollX = currentScrollX;
}
if (this._prevMinScrollY != this.scroller.minScrollY && currentScrollY < this.scroller.minScrollY) {
this.scroller.restrictedScrollY = currentScrollY;
} else if (this._prevMaxScrollY != this.scroller.maxScrollY && currentScrollY > this.scroller.maxScrollY) {
this.scroller.restrictedScrollY = currentScrollY;
}
if (currentScrollX != this.scroller.scrollX || currentScrollY != this.scroller.scrollY) {
// the scroll event from the scroller will be ignored at this point
// so we need to manually dispatch it
ScrollEvent.dispatch(this, ScrollEvent.SCROLL, false, false, this.scroller.scrollX, this.scroller.scrollY);
}
}

Expand Down
41 changes: 41 additions & 0 deletions test/src/feathers/controls/ScrollContainerFixedScrollBarsTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package feathers.controls;

import feathers.events.ScrollEvent;
import feathers.controls.HScrollBar;
import feathers.controls.LayoutGroup;
import feathers.controls.VScrollBar;
Expand Down Expand Up @@ -618,6 +619,46 @@ class ScrollContainerFixedScrollBarsTest extends Test {
this._container.validateNow();
}, IllegalOperationError);
}

public function testAutomaticRestrictScrollXToMaxScrollX():Void {
this._container.width = 100.0;
this._container.height = 100.0;
var child = new LayoutGroup();
child.width = 200.0;
child.height = 75.0;
this._container.addChild(child);
this._container.scrollX = 50.0;
this._container.validateNow();
child.width = 50.0;
var dispatchedScrollEvent = false;
this._container.addEventListener(ScrollEvent.SCROLL, function(event:ScrollEvent):Void {
dispatchedScrollEvent = true;
});
Assert.equals(50.0, this._container.scrollX);
this._container.validateNow();
Assert.equals(0.0, this._container.scrollX);
Assert.isTrue(dispatchedScrollEvent);
}

public function testAutomaticRestrictScrollYToMaxScrollY():Void {
this._container.width = 100.0;
this._container.height = 100.0;
var child = new LayoutGroup();
child.width = 75.0;
child.height = 200.0;
this._container.addChild(child);
this._container.scrollY = 50.0;
this._container.validateNow();
child.height = 50.0;
var dispatchedScrollEvent = false;
this._container.addEventListener(ScrollEvent.SCROLL, function(event:ScrollEvent):Void {
dispatchedScrollEvent = true;
});
Assert.equals(50.0, this._container.scrollY);
this._container.validateNow();
Assert.equals(0.0, this._container.scrollY);
Assert.isTrue(dispatchedScrollEvent);
}
}

private class ResizingHeightBox extends FeathersControl {
Expand Down

0 comments on commit c793f88

Please sign in to comment.