@@ -16,7 +16,9 @@ const trackWindowScroll = (BaseComponent) => {
16
16
constructor ( props ) {
17
17
super ( props ) ;
18
18
19
- if ( isIntersectionObserverAvailable ( ) ) {
19
+ this . useIntersectionObserver =
20
+ props . useIntersectionObserver && isIntersectionObserverAvailable ( ) ;
21
+ if ( this . useIntersectionObserver ) {
20
22
return ;
21
23
}
22
24
@@ -47,7 +49,7 @@ const trackWindowScroll = (BaseComponent) => {
47
49
}
48
50
49
51
componentDidUpdate ( ) {
50
- if ( typeof window === 'undefined' || isIntersectionObserverAvailable ( ) ) {
52
+ if ( typeof window === 'undefined' || this . useIntersectionObserver ) {
51
53
return ;
52
54
}
53
55
@@ -62,7 +64,7 @@ const trackWindowScroll = (BaseComponent) => {
62
64
}
63
65
64
66
addListeners ( ) {
65
- if ( typeof window === 'undefined' || isIntersectionObserverAvailable ( ) ) {
67
+ if ( typeof window === 'undefined' || this . useIntersectionObserver ) {
66
68
return ;
67
69
}
68
70
@@ -91,7 +93,7 @@ const trackWindowScroll = (BaseComponent) => {
91
93
}
92
94
93
95
removeListeners ( ) {
94
- if ( typeof window == 'undefined' || isIntersectionObserverAvailable ( ) ) {
96
+ if ( typeof window == 'undefined' || this . useIntersectionObserver ) {
95
97
return ;
96
98
}
97
99
@@ -104,7 +106,7 @@ const trackWindowScroll = (BaseComponent) => {
104
106
}
105
107
106
108
onChangeScroll ( ) {
107
- if ( isIntersectionObserverAvailable ( ) ) {
109
+ if ( this . useIntersectionObserver ) {
108
110
return ;
109
111
}
110
112
@@ -118,7 +120,7 @@ const trackWindowScroll = (BaseComponent) => {
118
120
119
121
render ( ) {
120
122
const { delayMethod, delayTime, ...props } = this . props ;
121
- const scrollPosition = isIntersectionObserverAvailable ( ) ?
123
+ const scrollPosition = this . useIntersectionObserver ?
122
124
null : this . state . scrollPosition ;
123
125
124
126
return (
@@ -133,11 +135,13 @@ const trackWindowScroll = (BaseComponent) => {
133
135
ScrollAwareComponent . propTypes = {
134
136
delayMethod : PropTypes . oneOf ( [ 'debounce' , 'throttle' ] ) ,
135
137
delayTime : PropTypes . number ,
138
+ useIntersectionObserver : PropTypes . bool ,
136
139
} ;
137
140
138
141
ScrollAwareComponent . defaultProps = {
139
142
delayMethod : 'throttle' ,
140
143
delayTime : 300 ,
144
+ useIntersectionObserver : true ,
141
145
} ;
142
146
143
147
return ScrollAwareComponent ;
0 commit comments