From b8242e7a97951467443397f4b15e53c024c02af5 Mon Sep 17 00:00:00 2001 From: Johan Kasperi Date: Mon, 27 May 2024 20:54:30 +0200 Subject: [PATCH] refactor: use timeout instead of callback for exiting bug --- src/Tooltip.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Tooltip.tsx b/src/Tooltip.tsx index 6d921ff..2e281a4 100644 --- a/src/Tooltip.tsx +++ b/src/Tooltip.tsx @@ -19,7 +19,6 @@ import Animated, { useDerivedValue, useSharedValue, type BaseAnimationBuilder, - runOnJS, } from 'react-native-reanimated'; import { Pointer } from './Pointer'; @@ -78,8 +77,15 @@ export const Tooltip = React.memo((props: PropsWithChildren) => { } = props; const [delayedVisible, setDelayedVisible] = useState(visible); - if ((visible || !exiting) && visible !== delayedVisible) { - setDelayedVisible(visible); + if (visible !== delayedVisible) { + const duration = exiting?.getDuration(); + if (duration && !visible) { + setTimeout(() => { + setDelayedVisible(visible); + }, duration); + } else { + setDelayedVisible(visible); + } } const element = useRef(null); @@ -251,15 +257,7 @@ export const Tooltip = React.memo((props: PropsWithChildren) => { /> {visible ? ( - { - 'worklet'; - if (finished) { - runOnJS(setDelayedVisible)(false); - } - })} - > +