Skip to content

Commit 540415f

Browse files
authored
Merge pull request Expensify#67294 from nkdengineer/fix/65702
prevent education tooltip from showing when the page is not focused
2 parents 3f7966f + 001dec4 commit 540415f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {NavigationContext} from '@react-navigation/native';
1+
import {NavigationContext, useIsFocused} from '@react-navigation/native';
22
import React, {memo, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState} from 'react';
33
import type {LayoutRectangle, NativeMethods, NativeSyntheticEvent} from 'react-native';
44
import {DeviceEventEmitter, Dimensions} from 'react-native';
@@ -27,12 +27,15 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
2727
const show = useRef<(() => void) | undefined>(undefined);
2828

2929
const navigator = useContext(NavigationContext);
30+
const isFocused = useIsFocused();
3031
const insets = useSafeAreaInsets();
3132

3233
const isResizing = useIsResizing();
3334

35+
const shouldSuppressTooltip = !isFocused && shouldHideOnNavigate;
36+
3437
const renderTooltip = useCallback(() => {
35-
if (!tooltipElementRef.current || !genericTooltipStateRef.current) {
38+
if (!tooltipElementRef.current || !genericTooltipStateRef.current || shouldSuppressTooltip) {
3639
return;
3740
}
3841

@@ -65,7 +68,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
6568
showTooltip();
6669
}
6770
});
68-
}, [insets]);
71+
}, [insets, shouldSuppressTooltip]);
6972

7073
useEffect(() => {
7174
if (!genericTooltipStateRef.current || !shouldRender) {
@@ -120,7 +123,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
120123
}, []);
121124

122125
useEffect(() => {
123-
if (!shouldMeasure) {
126+
if (!shouldMeasure || shouldSuppressTooltip) {
124127
return;
125128
}
126129
if (!shouldRender) {
@@ -134,7 +137,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
134137
return () => {
135138
clearTimeout(timerID);
136139
};
137-
}, [shouldMeasure, shouldRender]);
140+
}, [shouldMeasure, shouldRender, shouldSuppressTooltip]);
138141

139142
useEffect(() => {
140143
if (!navigator) {

0 commit comments

Comments
 (0)