diff --git a/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx b/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx index 69d68d32586e..9c9ca276797e 100644 --- a/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx +++ b/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx @@ -113,8 +113,8 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav {...props} > {(genericTooltipState) => { - // eslint-disable-next-line react-compiler/react-compiler const {updateTargetBounds, showTooltip} = genericTooltipState; + // eslint-disable-next-line react-compiler/react-compiler genericTooltipStateRef.current = genericTooltipState; return React.cloneElement(children as React.ReactElement, { onLayout: (e: LayoutChangeEventWithTarget) => { diff --git a/src/hooks/useScrollEventEmitter.ts b/src/hooks/useScrollEventEmitter.ts index 064181fc0518..6433dca823aa 100644 --- a/src/hooks/useScrollEventEmitter.ts +++ b/src/hooks/useScrollEventEmitter.ts @@ -6,14 +6,10 @@ import CONST from '@src/CONST'; * This hook tracks scroll events and emits a "scrolling" event when scrolling starts and ends. */ const useScrollEventEmitter = (additinalEmitData: T) => { - const [lastScrollEvent, setLastScrollEvent] = useState(null); const isScrollingRef = useRef(false); + let timeout: NodeJS.Timeout | null = null; // Timeout for detecting the end of scrolling const triggerScrollEvent = useCallback(() => { - setLastScrollEvent(Date.now()); - }, []); - - useEffect(() => { const emitScrolling = (isScrolling: boolean) => { DeviceEventEmitter.emit(CONST.EVENTS.SCROLLING, { isScrolling, @@ -28,13 +24,19 @@ const useScrollEventEmitter = (additinalEmitData: T) => { } // End the scroll and emit after a brief timeout to detect the end of scrolling - const timeout = setTimeout(() => { + if (timeout) { + clearTimeout(timeout); // Clear any existing timeout + } + + timeout = setTimeout(() => { emitScrolling(false); isScrollingRef.current = false; }, 250); + }, [additinalEmitData]); - return () => clearTimeout(timeout); - }, [lastScrollEvent]); + useEffect(() => { + triggerScrollEvent(); + }, [triggerScrollEvent]); return triggerScrollEvent; }; diff --git a/src/pages/Search/SearchPageBottomTab.tsx b/src/pages/Search/SearchPageBottomTab.tsx index b3b8fdfa6849..c61e79d77c1d 100644 --- a/src/pages/Search/SearchPageBottomTab.tsx +++ b/src/pages/Search/SearchPageBottomTab.tsx @@ -48,6 +48,7 @@ function SearchPageBottomTab() { const scrollHandler = useAnimatedScrollHandler({ onScroll: (event) => { + runOnJS(triggerScrollEvent)(); const {contentOffset, layoutMeasurement, contentSize} = event; if (windowHeight > contentSize.height) { return; @@ -65,7 +66,6 @@ function SearchPageBottomTab() { ); } scrollOffset.set(currentOffset); - runOnJS(triggerScrollEvent)(); }, });