Skip to content
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 @@ -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