Skip to content

Commit bd1f7b8

Browse files
authored
Merge pull request #9 from Expensify/Rory-FixNestedScrollInInvertedFlatList
Fix nested scroll in inverted VirtualizedList
2 parents 154f2cc + 532dd53 commit bd1f7b8

File tree

1 file changed

+19
-2
lines changed
  • packages/react-native-web/src/vendor/react-native/VirtualizedList

1 file changed

+19
-2
lines changed

packages/react-native-web/src/vendor/react-native/VirtualizedList/index.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -810,12 +810,29 @@ class VirtualizedList extends React.PureComponent<Props, State> {
810810
// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
811811
// For issue https://github.com/necolas/react-native-web/issues/995
812812
this.invertedWheelEventHandler = (ev: any) => {
813+
const scrollOffset = this.props.horizontal ? ev.target.scrollLeft : ev.target.scrollTop;
814+
const scrollLength = this.props.horizontal ? ev.target.scrollWidth : ev.target.scrollHeight;
815+
const clientLength = this.props.horizontal ? ev.target.clientWidth : ev.target.clientHeight;
816+
const isEventTargetScrollable = scrollLength > clientLength;
817+
const delta = this.props.horizontal
818+
? ev.deltaX || ev.wheelDeltaX
819+
: ev.deltaY || ev.wheelDeltaY;
820+
let leftoverDelta = delta;
821+
if (isEventTargetScrollable) {
822+
leftoverDelta = delta < 0
823+
? Math.min(delta + scrollOffset, 0)
824+
: Math.max(delta - (scrollLength - clientLength - scrollOffset), 0);
825+
}
826+
const targetDelta = delta - leftoverDelta;
827+
813828
if (this.props.inverted && this._scrollRef && this._scrollRef.getScrollableNode) {
814829
const node = (this._scrollRef: any).getScrollableNode();
815830
if (this.props.horizontal) {
816-
node.scrollLeft -= ev.deltaX || ev.wheelDeltaX
831+
ev.target.scrollLeft += targetDelta;
832+
node.scrollLeft -= leftoverDelta;
817833
} else {
818-
node.scrollTop -= ev.deltaY || ev.wheelDeltaY
834+
ev.target.scrollTop += targetDelta;
835+
node.scrollTop -= leftoverDelta;
819836
}
820837
ev.preventDefault();
821838
}

0 commit comments

Comments
 (0)