7
7
ALIGN_START ,
8
8
DIRECTION_VERTICAL ,
9
9
DIRECTION_HORIZONTAL ,
10
+ SCROLL_CHANGE_OBSERVED ,
11
+ SCROLL_CHANGE_REQUESTED ,
10
12
positionProp ,
11
13
scrollProp ,
12
14
sizeProp ,
@@ -48,6 +50,7 @@ export default class VirtualList extends PureComponent {
48
50
this . props . scrollToIndex != null && this . getOffsetForIndex ( this . props . scrollToIndex ) ||
49
51
0
50
52
) ,
53
+ scrollChangeReason : SCROLL_CHANGE_REQUESTED ,
51
54
} ;
52
55
53
56
_styleCache = { } ;
@@ -102,21 +105,23 @@ export default class VirtualList extends PureComponent {
102
105
if ( nextProps . scrollOffset !== scrollOffset ) {
103
106
this . setState ( {
104
107
offset : nextProps . scrollOffset ,
108
+ scrollChangeReason : SCROLL_CHANGE_REQUESTED ,
105
109
} ) ;
106
110
} else if (
107
111
scrollPropsHaveChanged ||
108
112
nextProps . scrollToIndex && itemPropsHaveChanged
109
113
) {
110
114
this . setState ( {
111
115
offset : this . getOffsetForIndex ( nextProps . scrollToIndex , nextProps . scrollToAlignment , nextProps . itemCount ) ,
116
+ scrollChangeReason : SCROLL_CHANGE_REQUESTED ,
112
117
} ) ;
113
118
}
114
119
}
115
120
116
121
componentDidUpdate ( nextProps , nextState ) {
117
122
const { offset} = this . state ;
118
123
119
- if ( nextState . offset !== offset ) {
124
+ if ( nextState . offset !== offset && nextState . scrollChangeReason === SCROLL_CHANGE_REQUESTED ) {
120
125
this . scrollTo ( offset ) ;
121
126
}
122
127
}
@@ -125,7 +130,14 @@ export default class VirtualList extends PureComponent {
125
130
const { onScroll} = this . props ;
126
131
const offset = this . getNodeOffset ( ) ;
127
132
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
+ } ) ;
129
141
130
142
if ( typeof onScroll === 'function' ) {
131
143
onScroll ( offset , e ) ;
0 commit comments