Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit6789 committed Feb 2, 2025
1 parent e2c6159 commit 6e4d316
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
18 changes: 10 additions & 8 deletions src/hooks/useScrollEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T extends Object>(additinalEmitData: T) => {
const [lastScrollEvent, setLastScrollEvent] = useState<number | null>(null);
const isScrollingRef = useRef<boolean>(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,
Expand All @@ -28,13 +24,19 @@ const useScrollEventEmitter = <T extends Object>(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;
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/SearchPageBottomTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function SearchPageBottomTab() {

const scrollHandler = useAnimatedScrollHandler({
onScroll: (event) => {
runOnJS(triggerScrollEvent)();
const {contentOffset, layoutMeasurement, contentSize} = event;
if (windowHeight > contentSize.height) {
return;
Expand All @@ -65,7 +66,6 @@ function SearchPageBottomTab() {
);
}
scrollOffset.set(currentOffset);
runOnJS(triggerScrollEvent)();
},
});

Expand Down

0 comments on commit 6e4d316

Please sign in to comment.