@@ -23,6 +23,8 @@ import debounce from 'lodash/debounce';
23
23
24
24
import { cssModules , isRTL } from '../../bpk-react-utils' ;
25
25
26
+ import type { DebouncedFunc } from 'lodash' ;
27
+
26
28
import STYLES from './BpkMobileScrollContainer.module.scss' ;
27
29
28
30
const getClassName = cssModules ( STYLES ) ;
@@ -84,6 +86,8 @@ type State = {
84
86
} ;
85
87
86
88
class BpkMobileScrollContainer extends Component < Props , State > {
89
+ debouncedResize : DebouncedFunc < ( ) => void >
90
+
87
91
static defaultProps : Partial < Props > = {
88
92
innerContainerTagName : 'div' ,
89
93
showScrollbar : false ,
@@ -96,24 +100,26 @@ class BpkMobileScrollContainer extends Component<Props, State> {
96
100
computedHeight : 'auto' ,
97
101
scrollIndicatorClassName : null ,
98
102
} ;
103
+
104
+ this . debouncedResize = debounce ( this . onWindowResize , 100 ) ;
99
105
}
100
106
101
107
componentDidMount ( ) {
102
108
requestAnimationFrame ( ( ) => {
103
109
this . setScrollBarAwareHeight ( ) ;
104
110
this . setScrollIndicatorClassName ( ) ;
105
111
} ) ;
106
- window . addEventListener ( 'resize' , this . onWindowResize ) ;
112
+ window . addEventListener ( 'resize' , this . debouncedResize ) ;
107
113
}
108
114
109
115
componentWillUnmount ( ) {
110
- window . removeEventListener ( 'resize' , this . onWindowResize ) ;
116
+ window . removeEventListener ( 'resize' , this . debouncedResize ) ;
111
117
}
112
118
113
- onWindowResize = debounce ( ( ) => {
119
+ onWindowResize = ( ) => {
114
120
this . setScrollBarAwareHeight ( ) ;
115
121
this . setScrollIndicatorClassName ( ) ;
116
- } , 100 ) ;
122
+ } ;
117
123
118
124
setScrollIndicatorClassName = ( ) => {
119
125
const classNames = computeScrollIndicatorClassName (
0 commit comments