Skip to content

Commit 37f14af

Browse files
author
Eric Vallee
committed
Fixed scrolling for Firefox by adding scroll context in state
1 parent 7dd4de8 commit 37f14af

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-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: 7 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
}
@@ -129,7 +134,7 @@ export default class VirtualList extends PureComponent {
129134
return;
130135
}
131136

132-
this.setState({offset});
137+
this.setState({offset, scrollChangeReason: SCROLL_CHANGE_OBSERVED});
133138

134139
if (typeof onScroll === 'function') {
135140
onScroll(offset, e);

0 commit comments

Comments
 (0)