@@ -96,6 +96,8 @@ var InfiniteScroll = (function(_Component) {
9696 ) ;
9797
9898 _this . scrollListener = _this . scrollListener . bind ( _this ) ;
99+ _this . eventListenerOptions = _this . eventListenerOptions . bind ( _this ) ;
100+ _this . mousewheelListener = _this . mousewheelListener . bind ( _this ) ;
99101 return _this ;
100102 }
101103
@@ -104,6 +106,7 @@ var InfiniteScroll = (function(_Component) {
104106 key : 'componentDidMount' ,
105107 value : function componentDidMount ( ) {
106108 this . pageLoaded = this . props . pageStart ;
109+ this . options = this . eventListenerOptions ( ) ;
107110 this . attachScrollListener ( ) ;
108111 }
109112 } ,
@@ -126,8 +129,40 @@ var InfiniteScroll = (function(_Component) {
126129 value : function componentWillUnmount ( ) {
127130 this . detachScrollListener ( ) ;
128131 this . detachMousewheelListener ( ) ;
129- }
132+ } ,
133+ } ,
134+ {
135+ key : 'isPassiveSupported' ,
136+ value : function isPassiveSupported ( ) {
137+ var passive = false ;
138+
139+ var testOptions = {
140+ get passive ( ) {
141+ passive = true ;
142+ } ,
143+ } ;
130144
145+ try {
146+ document . addEventListener ( 'test' , null , testOptions ) ;
147+ } catch ( e ) {
148+ // ignore
149+ }
150+ return passive ;
151+ } ,
152+ } ,
153+ {
154+ key : 'eventListenerOptions' ,
155+ value : function eventListenerOptions ( ) {
156+ var options = false ;
157+
158+ if ( this . isPassiveSupported ( ) ) {
159+ options = {
160+ useCapture : this . props . useCapture ,
161+ passive : this . props . passive ,
162+ } ;
163+ }
164+ return options ;
165+ }
131166 // Set a defaut loader for all your `InfiniteScroll` components
132167 } ,
133168 {
@@ -147,7 +182,7 @@ var InfiniteScroll = (function(_Component) {
147182 scrollEl . removeEventListener (
148183 'mousewheel' ,
149184 this . mousewheelListener ,
150- this . props . useCapture
185+ this . options ? this . options : this . props . useCapture
151186 ) ;
152187 }
153188 } ,
@@ -162,12 +197,12 @@ var InfiniteScroll = (function(_Component) {
162197 scrollEl . removeEventListener (
163198 'scroll' ,
164199 this . scrollListener ,
165- this . props . useCapture
200+ this . options ? this . options : this . props . useCapture
166201 ) ;
167202 scrollEl . removeEventListener (
168203 'resize' ,
169204 this . scrollListener ,
170- this . props . useCapture
205+ this . options ? this . options : this . props . useCapture
171206 ) ;
172207 }
173208 } ,
@@ -205,17 +240,17 @@ var InfiniteScroll = (function(_Component) {
205240 scrollEl . addEventListener (
206241 'mousewheel' ,
207242 this . mousewheelListener ,
208- this . props . useCapture
243+ this . options ? this . options : this . props . useCapture ,
209244 ) ;
210245 scrollEl . addEventListener (
211246 'scroll' ,
212247 this . scrollListener ,
213- this . props . useCapture
248+ this . options ? this . options : this . props . useCapture ,
214249 ) ;
215250 scrollEl . addEventListener (
216251 'resize' ,
217252 this . scrollListener ,
218- this . props . useCapture
253+ this . options ? this . options : this . props . useCapture
219254 ) ;
220255
221256 if ( this . props . initialLoad ) {
@@ -228,7 +263,10 @@ var InfiniteScroll = (function(_Component) {
228263 value : function mousewheelListener ( e ) {
229264 // Prevents Chrome hangups
230265 // See: https://stackoverflow.com/questions/47524205/random-high-content-download-time-in-chrome/47684257#47684257
231- if ( e . deltaY === 1 ) {
266+ if (
267+ e . deltaY === 1 &&
268+ ( ! this . props . passive || ! this . isPassiveSupported ( ) )
269+ ) {
232270 e . preventDefault ( ) ;
233271 }
234272 }
0 commit comments