Skip to content

Commit f7cf6f9

Browse files
committed
prevent education tooltip from showing when the page is not focused
1 parent 44d8ae5 commit f7cf6f9

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx

Lines changed: 6 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,13 @@ 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

3435
const renderTooltip = useCallback(() => {
35-
if (!tooltipElementRef.current || !genericTooltipStateRef.current) {
36+
if (!tooltipElementRef.current || !genericTooltipStateRef.current || (!isFocused && shouldHideOnNavigate)) {
3637
return;
3738
}
3839

@@ -65,7 +66,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
6566
showTooltip();
6667
}
6768
});
68-
}, [insets]);
69+
}, [insets.bottom, insets.left, insets.right, insets.top, isFocused, shouldHideOnNavigate]);
6970

7071
useEffect(() => {
7172
if (!genericTooltipStateRef.current || !shouldRender) {
@@ -120,7 +121,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
120121
}, []);
121122

122123
useEffect(() => {
123-
if (!shouldMeasure) {
124+
if (!shouldMeasure || (!isFocused && shouldHideOnNavigate)) {
124125
return;
125126
}
126127
if (!shouldRender) {
@@ -134,7 +135,7 @@ function BaseEducationalTooltip({children, shouldRender = false, shouldHideOnNav
134135
return () => {
135136
clearTimeout(timerID);
136137
};
137-
}, [shouldMeasure, shouldRender]);
138+
}, [shouldMeasure, shouldRender, isFocused, shouldHideOnNavigate]);
138139

139140
useEffect(() => {
140141
if (!navigator) {

0 commit comments

Comments
 (0)