mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-26 15:58:28 +00:00
[fix] inverted VirtualizedList supports wheel events
Close #2223 Close #1241 Fix #995
This commit is contained in:
committed by
Nicolas Gallagher
parent
17241dbcfa
commit
7ec2489c78
+37
-1
@@ -678,6 +678,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|||||||
|
|
||||||
state: State;
|
state: State;
|
||||||
|
|
||||||
|
invertedWheelEventHandler: ?(ev: any) => void;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
invariant(
|
invariant(
|
||||||
@@ -731,6 +733,19 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
this.state = initialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,6 +762,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|||||||
parentDebugInfo: this.context.debugInfo,
|
parentDebugInfo: this.context.debugInfo,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.setupWebWheelHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@@ -766,6 +782,26 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|||||||
tuple.viewabilityHelper.dispose();
|
tuple.viewabilityHelper.dispose();
|
||||||
});
|
});
|
||||||
this._fillRateHelper.deactivateAndFlush();
|
this._fillRateHelper.deactivateAndFlush();
|
||||||
|
this.teardownWebWheelHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
setupWebWheelHandler() {
|
||||||
|
if (this._scrollRef && this._scrollRef.getScrollableNode) {
|
||||||
|
this._scrollRef.getScrollableNode().addEventListener('wheel',
|
||||||
|
this.invertedWheelEventHandler
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setTimeout(() => this.setupWebWheelHandler(), 50);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
teardownWebWheelHandler() {
|
||||||
|
if (this._scrollRef && this._scrollRef.getScrollableNode) {
|
||||||
|
this._scrollRef.getScrollableNode().removeEventListener('wheel',
|
||||||
|
this.invertedWheelEventHandler
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(newProps: Props, prevState: State): State {
|
static getDerivedStateFromProps(newProps: Props, prevState: State): State {
|
||||||
@@ -2092,4 +2128,4 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default VirtualizedList;
|
export default VirtualizedList;
|
||||||
|
|||||||
Reference in New Issue
Block a user