1- import React , { useCallback , useEffect } from 'react' ;
1+ import React , { useCallback } from 'react' ;
22import { Dimensions , type LayoutChangeEvent } from 'react-native' ;
33import Animated , {
44 measure ,
@@ -10,10 +10,10 @@ import Animated, {
1010 useSharedValue ,
1111} from 'react-native-reanimated' ;
1212import { useAnimatedContext } from '../../../context/AnimatedContext' ;
13+ import { logger } from '../../../utils/logger' ;
1314import { useEnteringCallbacks } from '../hooks/useEnteringCallbacks' ;
1415import { useVisibilityCallbacks } from '../hooks/useVisibilityCallbacks' ;
1516import { LazyChildProps } from '../types' ;
16- import { logger } from '../../../utils/logger' ;
1717
1818const SCREEN_HEIGHT = Dimensions . get ( 'window' ) . height ;
1919
@@ -37,18 +37,9 @@ export function FullLazyChild({
3737 containerStart,
3838 containerEnd,
3939 horizontal,
40+ isScrollUnmounted,
4041 } = useAnimatedContext ( ) ;
4142
42- const _isMounted = useSharedValue ( false ) ;
43-
44- useEffect ( ( ) => {
45- _isMounted . value = true ;
46-
47- return ( ) => {
48- _isMounted . value = false ;
49- } ;
50- } , [ _isMounted ] ) ;
51-
5243 /**
5344 * If onLayout returns a height or width value greater than 0.
5445 */
@@ -64,25 +55,25 @@ export function FullLazyChild({
6455
6556 const _debug = useSharedValue ( debug ) ;
6657
67- const _shouldFireThresholdEnter = useSharedValue (
68- typeof onEnterThresholdPass === 'function'
69- ) ;
70- const _shouldFireThresholdExit = useSharedValue (
71- typeof onExitThresholdPass === 'function'
72- ) ;
73- const _shouldMeasurePercentVisible = useSharedValue (
74- typeof onVisibilityEnter === 'function'
75- ) ;
76- const _shouldFireVisibilityExit = useSharedValue (
77- typeof onVisibilityExit === 'function'
78- ) ;
58+ const shouldFireThresholdEnter = useDerivedValue ( ( ) => {
59+ return typeof onEnterThresholdPass === 'function' && ! isScrollUnmounted ;
60+ } ) ;
61+ const shouldFireThresholdExit = useDerivedValue ( ( ) => {
62+ return typeof onExitThresholdPass === 'function' && ! isScrollUnmounted ;
63+ } ) ;
64+ const shouldMeasurePercentVisible = useDerivedValue ( ( ) => {
65+ return typeof onVisibilityEnter === 'function' && ! isScrollUnmounted ;
66+ } ) ;
67+ const shouldFireVisibilityExit = useDerivedValue ( ( ) => {
68+ return typeof onVisibilityExit === 'function' && ! isScrollUnmounted ;
69+ } ) ;
7970
8071 const _hasValidCallback = useDerivedValue (
8172 ( ) =>
82- _shouldFireThresholdEnter . value ||
83- _shouldFireThresholdExit . value ||
84- _shouldMeasurePercentVisible . value ||
85- _shouldFireVisibilityExit . value
73+ shouldFireThresholdEnter . value ||
74+ shouldFireThresholdExit . value ||
75+ shouldMeasurePercentVisible . value ||
76+ shouldFireVisibilityExit . value
8677 ) ;
8778
8879 function measureView ( ) {
@@ -123,8 +114,8 @@ export function FullLazyChild({
123114 onEnterThresholdPass,
124115 onExitThresholdPass,
125116 _measurement,
126- _shouldFireThresholdEnter ,
127- _shouldFireThresholdExit ,
117+ shouldFireThresholdEnter ,
118+ shouldFireThresholdExit ,
128119 startTrigger,
129120 endTrigger,
130121 horizontal,
@@ -134,8 +125,8 @@ export function FullLazyChild({
134125 percentVisibleThreshold,
135126 onVisibilityEnter,
136127 onVisibilityExit,
137- _shouldMeasurePercentVisible ,
138- _shouldFireVisibilityExit ,
128+ shouldMeasurePercentVisible ,
129+ shouldFireVisibilityExit ,
139130 _measurement,
140131 containerStart,
141132 containerEnd,
0 commit comments