Skip to content

Commit c9cd548

Browse files
committed
fix: visibility ms not firing
1 parent 73a627d commit c9cd548

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/components/LazyChild/hooks/useVisibilityCallbacks.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
useAnimatedReaction,
88
useDerivedValue,
99
useSharedValue,
10-
withDelay,
1110
withTiming,
1211
} from 'react-native-reanimated';
1312

@@ -102,28 +101,33 @@ export const useVisibilityCallbacks = ({
102101

103102
useAnimatedReaction(
104103
() => _isVisible.value,
105-
(isLazyChildVisible) => {
106-
if (isLazyChildVisible) {
104+
(isLazyChildVisible, prevIsVisible) => {
105+
if (isLazyChildVisible && !prevIsVisible) {
107106
if (shouldMeasurePercentVisible.value) {
108107
if (_visibilityTimer.value > 0) {
109108
cancelAnimation(_visibilityTimer);
110109
_visibilityTimer.value = 0;
111110
}
112111

113-
if (minimumVisibilityMs) {
114-
_visibilityTimer.value = withDelay(
115-
minimumVisibilityMs,
116-
withTiming(1, { duration: 0 }, (finished) => {
112+
if (minimumVisibilityMs && minimumVisibilityMs > 0) {
113+
_visibilityTimer.value = withTiming(
114+
1,
115+
{ duration: minimumVisibilityMs },
116+
(finished) => {
117117
if (finished) {
118118
runOnJS(handleOnVisibilityEntered)();
119119
}
120-
})
120+
}
121121
);
122122
} else {
123123
runOnJS(handleOnVisibilityEntered)();
124124
}
125125
}
126-
} else {
126+
}
127+
128+
if (!isLazyChildVisible && prevIsVisible) {
129+
cancelAnimation(_visibilityTimer);
130+
127131
if (shouldFireVisibilityExit.value) {
128132
runOnJS(handleOnVisibilityExited)();
129133
}

0 commit comments

Comments
 (0)