Skip to content

Commit

Permalink
undo runHoverAfterInteraction
Browse files Browse the repository at this point in the history
  • Loading branch information
perunt committed Jan 10, 2024
1 parent abe9dc4 commit 4987167
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
31 changes: 7 additions & 24 deletions src/components/Hoverable/ActiveHoverable.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
import type {Ref} from 'react';
import {cloneElement, forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {DeviceEventEmitter, InteractionManager} from 'react-native';
import {DeviceEventEmitter} from 'react-native';
import mergeRefs from '@libs/mergeRefs';
import {getReturnValue} from '@libs/ValueUtils';
import CONST from '@src/CONST';
import type HoverableProps from './types';

type ActiveHoverableProps = Omit<HoverableProps, 'disabled'>;
type UseHoveredReturnType = [boolean, (newValue: boolean) => void];
// This is a workaround specifically for the web part of comment linking. Without this adjustment, you might observe sliding effects due to conflicts between MVCPFlatList implementation and this file. Check it once https://github.com/necolas/react-native-web/pull/2588 is merged
function useHovered(initialValue: boolean, runHoverAfterInteraction: boolean): UseHoveredReturnType {
const [state, setState] = useState(initialValue);

const interceptedSetState = useCallback((newValue: boolean) => {
if (runHoverAfterInteraction) {
InteractionManager.runAfterInteractions(() => {
setState(newValue);
});
} else {
setState(newValue);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return [state, interceptedSetState];
}

function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, children, runHoverAfterInteraction = false}: ActiveHoverableProps, outerRef: Ref<HTMLElement>) {
const [isHovered, setIsHovered] = useHovered(false, runHoverAfterInteraction);
function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, children}: ActiveHoverableProps, outerRef: Ref<HTMLElement>) {
const [isHovered, setIsHovered] = useState(false);

const elementRef = useRef<HTMLElement | null>(null);
const isScrollingRef = useRef(false);
Expand All @@ -40,7 +23,7 @@ function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, children, r
}
setIsHovered(hovered);
},
[setIsHovered, shouldHandleScroll],
[shouldHandleScroll],
);

useEffect(() => {
Expand All @@ -64,7 +47,7 @@ function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, children, r
});

return () => scrollingListener.remove();
}, [setIsHovered, shouldHandleScroll]);
}, [shouldHandleScroll]);

useEffect(() => {
// Do not mount a listener if the component is not hovered
Expand All @@ -89,7 +72,7 @@ function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, children, r
document.addEventListener('mouseover', unsetHoveredIfOutside);

return () => document.removeEventListener('mouseover', unsetHoveredIfOutside);
}, [setIsHovered, isHovered, elementRef]);
}, [isHovered, elementRef]);

useEffect(() => {
const unsetHoveredWhenDocumentIsHidden = () => document.visibilityState === 'hidden' && setIsHovered(false);
Expand Down Expand Up @@ -130,7 +113,7 @@ function ActiveHoverable({onHoverIn, onHoverOut, shouldHandleScroll, children, r

child.props.onBlur?.(event);
},
[setIsHovered, child.props],
[child.props],
);

return cloneElement(child, {
Expand Down
32 changes: 0 additions & 32 deletions src/libs/migrations/CheckForPreviousReportActionIDClean.ts

This file was deleted.

0 comments on commit 4987167

Please sign in to comment.