@@ -31,14 +31,19 @@ const AutoScrolling = ({
31
31
const [ isAutoScrolling , setIsAutoScrolling ] = React . useState ( false ) ;
32
32
const [ dividerWidth , setDividerWidth ] = React . useState ( endPaddingWidth ) ;
33
33
const offsetX = React . useRef ( new Animated . Value ( 0 ) ) ;
34
- let contentRef : any ;
34
+ const contentRef = React . useRef ( 0 ) ;
35
+
36
+ React . useEffect ( ( ) => {
37
+ // Clean up to avoid calling measureContainerView after unmount.
38
+ return ( ) => ( contentRef . current = 0 ) ;
39
+ } ) ;
35
40
36
41
function measureContainerView ( event : LayoutChangeEvent ) {
37
42
const newContainerWidth = event . nativeEvent . layout . width ;
38
43
if ( containerWidth . current === newContainerWidth ) return ;
39
44
containerWidth . current = newContainerWidth ;
40
- if ( ! contentRef ) return ;
41
- contentRef . measure ( ( fx : number , fy : number , width : number ) => {
45
+ if ( ! contentRef . current ) return ;
46
+ contentRef . current . measure ( ( fx : number , fy : number , width : number ) => {
42
47
checkContent ( width , fx ) ;
43
48
} ) ;
44
49
}
@@ -87,7 +92,7 @@ const AutoScrolling = ({
87
92
const childrenWithProps = React . cloneElement ( children , {
88
93
...childrenProps ,
89
94
onLayout : measureContentView ,
90
- ref : ( ref : any ) => ( contentRef = ref ) ,
95
+ ref : ( ref : any ) => ( contentRef . current = ref ) ,
91
96
} ) ;
92
97
93
98
return (
0 commit comments