Skip to content

Commit 1a07b70

Browse files
author
Claudéric Demers
authored
Merge pull request #7 from Magnitus-/master
Fix for Scrolling With Firefox Under Windows/Ubuntu
2 parents 74aa453 + d76d839 commit 1a07b70

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export const ALIGN_CENTER = 'center';
33
export const ALIGN_END = 'end';
44
export const DIRECTION_VERTICAL = 'vertical';
55
export const DIRECTION_HORIZONTAL = 'horizontal';
6+
export const SCROLL_CHANGE_OBSERVED = 'observed';
7+
export const SCROLL_CHANGE_REQUESTED = 'requested';
68

79
export const scrollProp = {
810
[DIRECTION_VERTICAL]: 'scrollTop',

src/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
ALIGN_START,
88
DIRECTION_VERTICAL,
99
DIRECTION_HORIZONTAL,
10+
SCROLL_CHANGE_OBSERVED,
11+
SCROLL_CHANGE_REQUESTED,
1012
positionProp,
1113
scrollProp,
1214
sizeProp,
@@ -48,6 +50,7 @@ export default class VirtualList extends PureComponent {
4850
this.props.scrollToIndex != null && this.getOffsetForIndex(this.props.scrollToIndex) ||
4951
0
5052
),
53+
scrollChangeReason: SCROLL_CHANGE_REQUESTED,
5154
};
5255

5356
_styleCache = {};
@@ -102,21 +105,23 @@ export default class VirtualList extends PureComponent {
102105
if (nextProps.scrollOffset !== scrollOffset) {
103106
this.setState({
104107
offset: nextProps.scrollOffset,
108+
scrollChangeReason: SCROLL_CHANGE_REQUESTED,
105109
});
106110
} else if (
107111
scrollPropsHaveChanged ||
108112
nextProps.scrollToIndex && itemPropsHaveChanged
109113
) {
110114
this.setState({
111115
offset: this.getOffsetForIndex(nextProps.scrollToIndex, nextProps.scrollToAlignment, nextProps.itemCount),
116+
scrollChangeReason: SCROLL_CHANGE_REQUESTED,
112117
});
113118
}
114119
}
115120

116121
componentDidUpdate(nextProps, nextState) {
117122
const {offset} = this.state;
118123

119-
if (nextState.offset !== offset) {
124+
if (nextState.offset !== offset && nextState.scrollChangeReason === SCROLL_CHANGE_REQUESTED) {
120125
this.scrollTo(offset);
121126
}
122127
}
@@ -125,7 +130,14 @@ export default class VirtualList extends PureComponent {
125130
const {onScroll} = this.props;
126131
const offset = this.getNodeOffset();
127132

128-
this.setState({offset});
133+
if (offset < 0 || this.state.offset === offset || e.target !== this.rootNode) {
134+
return;
135+
}
136+
137+
this.setState({
138+
offset,
139+
scrollChangeReason: SCROLL_CHANGE_OBSERVED,
140+
});
129141

130142
if (typeof onScroll === 'function') {
131143
onScroll(offset, e);

0 commit comments

Comments
 (0)