From 14a335ef35d3a15fed14eeafa61d11794b0245d0 Mon Sep 17 00:00:00 2001 From: Rayane Djouah <77965000+rayane-djouah@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:00:02 +0100 Subject: [PATCH] Fix crash --- .../EducationalTooltip/BaseEducationalTooltip.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx b/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx index c1298a19e9dd..a51275de9870 100644 --- a/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx +++ b/src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx @@ -1,5 +1,5 @@ -import {useNavigation} from '@react-navigation/native'; -import React, {memo, useEffect, useRef, useState} from 'react'; +import {NavigationContext} from '@react-navigation/native'; +import React, {memo, useContext, useEffect, useRef, useState} from 'react'; import type {LayoutRectangle, NativeSyntheticEvent} from 'react-native'; import GenericTooltip from '@components/Tooltip/GenericTooltip'; import type {EducationalTooltipProps} from '@components/Tooltip/types'; @@ -17,7 +17,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav const [shouldMeasure, setShouldMeasure] = useState(false); const show = useRef<() => void>(); - const navigation = useNavigation(); + const navigator = useContext(NavigationContext); useEffect(() => { return () => { @@ -43,14 +43,17 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav }, [shouldMeasure, shouldRender]); useEffect(() => { - const unsubscribe = navigation.addListener('blur', () => { + if (!navigator) { + return; + } + const unsubscribe = navigator.addListener('blur', () => { if (!shouldHideOnNavigate) { return; } hideTooltipRef.current?.(); }); return unsubscribe; - }, [navigation, shouldHideOnNavigate]); + }, [navigator, shouldHideOnNavigate]); return (