Skip to content

Commit 2a22624

Browse files
SkylerBaekseunghoh
authored andcommitted
PLAT-48029: Added reachedEdgeInfo within onScrollStop callback (#1933)
* PLAT-48029: Added reachedEdgeInfo within `onScrollStop` callback * Cleared code * Cleared code
1 parent e26ca00 commit 2a22624

File tree

2 files changed

+72
-8
lines changed

2 files changed

+72
-8
lines changed

packages/ui/Scrollable/Scrollable.js

+36-4
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class ScrollableBase extends Component {
461461
componentWillUnmount () {
462462
// Before call cancelAnimationFrame, you must send scrollStop Event.
463463
if (this.animator.isAnimating()) {
464-
this.forwardScrollEvent('onScrollStop');
464+
this.forwardScrollEvent('onScrollStop', this.getReachedEdgeInfo());
465465
this.animator.stop();
466466
}
467467

@@ -823,8 +823,8 @@ class ScrollableBase extends Component {
823823

824824
// call scroll callbacks
825825

826-
forwardScrollEvent (type) {
827-
forward(type, {scrollLeft: this.scrollLeft, scrollTop: this.scrollTop, moreInfo: this.getMoreInfo()}, this.props);
826+
forwardScrollEvent (type, reachedEdgeInfo) {
827+
forward(type, {scrollLeft: this.scrollLeft, scrollTop: this.scrollTop, moreInfo: this.getMoreInfo(), reachedEdgeInfo}, this.props);
828828
}
829829

830830
// update scroll position
@@ -857,6 +857,38 @@ class ScrollableBase extends Component {
857857
}
858858
}
859859

860+
getReachedEdgeInfo = () => {
861+
const
862+
bounds = this.getScrollBounds(),
863+
reachedEdgeInfo = {bottom: false, left: false, right: false, top: false};
864+
865+
if (this.canScrollHorizontally(bounds)) {
866+
const
867+
rtl = this.state.rtl,
868+
edge = this.getEdgeFromPosition(this.scrollLeft, bounds.maxLeft);
869+
870+
if (edge) { // if edge is null, no need to check which edge is reached.
871+
if ((edge === 'before' && !rtl) || (edge === 'after' && rtl)) {
872+
reachedEdgeInfo.left = true;
873+
} else {
874+
reachedEdgeInfo.right = true;
875+
}
876+
}
877+
}
878+
879+
if (this.canScrollVertically(bounds)) {
880+
const edge = this.getEdgeFromPosition(this.scrollTop, bounds.maxTop);
881+
882+
if (edge === 'before') {
883+
reachedEdgeInfo.top = true;
884+
} else if (edge === 'after') {
885+
reachedEdgeInfo.bottom = true;
886+
}
887+
}
888+
889+
return reachedEdgeInfo;
890+
}
891+
860892
// scroll start/stop
861893

862894
start ({targetX, targetY, animate = true, duration = animationDuration, overscrollEffect = false}) {
@@ -973,7 +1005,7 @@ class ScrollableBase extends Component {
9731005
}
9741006
if (this.scrolling) {
9751007
this.scrolling = false;
976-
this.forwardScrollEvent('onScrollStop');
1008+
this.forwardScrollEvent('onScrollStop', this.getReachedEdgeInfo());
9771009
}
9781010
}
9791011

packages/ui/Scrollable/ScrollableNative.js

+36-4
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class ScrollableBaseNative extends Component {
461461
componentWillUnmount () {
462462
// Before call cancelAnimationFrame, you must send scrollStop Event.
463463
if (this.scrolling) {
464-
this.forwardScrollEvent('onScrollStop');
464+
this.forwardScrollEvent('onScrollStop', this.getReachedEdgeInfo());
465465
}
466466
this.scrollStopJob.stop();
467467

@@ -907,8 +907,8 @@ class ScrollableBaseNative extends Component {
907907

908908
// call scroll callbacks
909909

910-
forwardScrollEvent (type) {
911-
forward(type, {scrollLeft: this.scrollLeft, scrollTop: this.scrollTop, moreInfo: this.getMoreInfo()}, this.props);
910+
forwardScrollEvent (type, reachedEdgeInfo) {
911+
forward(type, {scrollLeft: this.scrollLeft, scrollTop: this.scrollTop, moreInfo: this.getMoreInfo(), reachedEdgeInfo}, this.props);
912912
}
913913

914914
// call scroll callbacks and update scrollbars for native scroll
@@ -929,7 +929,7 @@ class ScrollableBaseNative extends Component {
929929
this.lastInputType = null;
930930
this.isScrollAnimationTargetAccumulated = false;
931931
this.scrolling = false;
932-
this.forwardScrollEvent('onScrollStop');
932+
this.forwardScrollEvent('onScrollStop', this.getReachedEdgeInfo());
933933
this.startHidingThumb();
934934
}
935935

@@ -999,6 +999,38 @@ class ScrollableBaseNative extends Component {
999999
}
10001000
}
10011001

1002+
getReachedEdgeInfo = () => {
1003+
const
1004+
bounds = this.getScrollBounds(),
1005+
reachedEdgeInfo = {bottom: false, left: false, right: false, top: false};
1006+
1007+
if (this.canScrollHorizontally(bounds)) {
1008+
const
1009+
rtl = this.state.rtl,
1010+
edge = this.getEdgeFromPosition(this.scrollLeft, bounds.maxLeft);
1011+
1012+
if (edge) { // if edge is null, no need to check which edge is reached.
1013+
if ((edge === 'before' && !rtl) || (edge === 'after' && rtl)) {
1014+
reachedEdgeInfo.left = true;
1015+
} else {
1016+
reachedEdgeInfo.right = true;
1017+
}
1018+
}
1019+
}
1020+
1021+
if (this.canScrollVertically(bounds)) {
1022+
const edge = this.getEdgeFromPosition(this.scrollTop, bounds.maxTop);
1023+
1024+
if (edge === 'before') {
1025+
reachedEdgeInfo.top = true;
1026+
} else if (edge === 'after') {
1027+
reachedEdgeInfo.bottom = true;
1028+
}
1029+
}
1030+
1031+
return reachedEdgeInfo;
1032+
}
1033+
10021034
// scroll start
10031035

10041036
start ({targetX, targetY, animate = true, overscrollEffect = false}) {

0 commit comments

Comments
 (0)