Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested scroll in inverted VirtualizedList #9

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,29 @@ class VirtualizedList extends React.PureComponent<Props, State> {
// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
// For issue https://github.com/necolas/react-native-web/issues/995
this.invertedWheelEventHandler = (ev: any) => {
const scrollOffset = this.props.horizontal ? ev.target.scrollLeft : ev.target.scrollTop;
const scrollLength = this.props.horizontal ? ev.target.scrollWidth : ev.target.scrollHeight;
const clientLength = this.props.horizontal ? ev.target.clientWidth : ev.target.clientHeight;
const isEventTargetScrollable = scrollLength > clientLength;
const delta = this.props.horizontal
? ev.deltaX || ev.wheelDeltaX
: ev.deltaY || ev.wheelDeltaY;
let leftoverDelta = delta;
if (isEventTargetScrollable) {
leftoverDelta = delta < 0
? Math.min(delta + scrollOffset, 0)
: Math.max(delta - (scrollLength - clientLength - scrollOffset), 0);
}
const targetDelta = delta - leftoverDelta;

if (this.props.inverted && this._scrollRef && this._scrollRef.getScrollableNode) {
const node = (this._scrollRef: any).getScrollableNode();
if (this.props.horizontal) {
node.scrollLeft -= ev.deltaX || ev.wheelDeltaX
ev.target.scrollLeft += targetDelta;
node.scrollLeft -= leftoverDelta;
} else {
node.scrollTop -= ev.deltaY || ev.wheelDeltaY
ev.target.scrollTop += targetDelta;
node.scrollTop -= leftoverDelta;
}
ev.preventDefault();
}
Expand Down