Skip to content

Commit

Permalink
Restore customization patch of VirtualizedList which inverts mouse wh…
Browse files Browse the repository at this point in the history
…eel scroll position while list is inverted. Added loud comments to make it clear this code intends to live on in RNW even though not present in RN.
  • Loading branch information
DavidRieman committed Mar 2, 2022
1 parent 6a2fa26 commit 33e4290
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {

state: State;

// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
invertedWheelEventHandler: ?(ev: any) => void;

constructor(props: Props) {
super(props);
invariant(
Expand Down Expand Up @@ -733,6 +736,20 @@ 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) => {
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
} else {
node.scrollTop -= ev.deltaY || ev.wheelDeltaY
}
ev.preventDefault();
}
};

this.state = initialState;
}

Expand All @@ -749,6 +766,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
parentDebugInfo: this.context.debugInfo,
});
}

// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
this.setupWebWheelHandler();
}

componentWillUnmount() {
Expand All @@ -768,6 +788,30 @@ class VirtualizedList extends React.PureComponent<Props, State> {
tuple.viewabilityHelper.dispose();
});
this._fillRateHelper.deactivateAndFlush();

// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
this.teardownWebWheelHandler();
}

// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
setupWebWheelHandler() {
if (this._scrollRef && this._scrollRef.getScrollableNode) {
this._scrollRef.getScrollableNode().addEventListener('wheel',
this.invertedWheelEventHandler
);
} else {
setTimeout(() => this.setupWebWheelHandler(), 50);
return
}
}

// REACT-NATIVE-WEB patch to preserve during future RN merges: Support inverted wheel scroller.
teardownWebWheelHandler() {
if (this._scrollRef && this._scrollRef.getScrollableNode) {
this._scrollRef.getScrollableNode().removeEventListener('wheel',
this.invertedWheelEventHandler
);
}
}

static getDerivedStateFromProps(newProps: Props, prevState: State): State {
Expand Down

0 comments on commit 33e4290

Please sign in to comment.