Skip to content

Commit f12dab1

Browse files
authored
Merge pull request #49913 from daledah/fix/49873
fix: tooltip reappears
2 parents fb91e4f + 5cd6086 commit f12dab1

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

src/components/LHNOptionsList/OptionRowLHN.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function OptionRowLHN({reportID, isFocused = false, onSelectRow = () => {}, opti
184184
shiftHorizontal={variables.gbrTooltipShiftHorizontal}
185185
shiftVertical={variables.composerTooltipShiftVertical}
186186
wrapperStyle={styles.quickActionTooltipWrapper}
187-
onHideTooltip={() => User.dismissGBRTooltip()}
187+
onHideTooltip={User.dismissGBRTooltip}
188188
>
189189
<View>
190190
<Hoverable>

src/components/Tooltip/EducationalTooltip/BaseEducationalTooltip.tsx

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React, {memo, useEffect, useRef, useState} from 'react';
1+
import React, {memo, useCallback, useEffect, useRef, useState} from 'react';
22
import type {LayoutRectangle, NativeSyntheticEvent} from 'react-native';
3-
import {useOnyx} from 'react-native-onyx';
43
import GenericTooltip from '@components/Tooltip/GenericTooltip';
54
import type {EducationalTooltipProps} from '@components/Tooltip/types';
5+
import onyxSubscribe from '@libs/onyxSubscribe';
66
import ONYXKEYS from '@src/ONYXKEYS';
7+
import type {Modal} from '@src/types/onyx';
78
import measureTooltipCoordinate from './measureTooltipCoordinate';
89

910
type LayoutChangeEventWithTarget = NativeSyntheticEvent<{layout: LayoutRectangle; target: HTMLElement}>;
@@ -12,14 +13,45 @@ type LayoutChangeEventWithTarget = NativeSyntheticEvent<{layout: LayoutRectangle
1213
* A component used to wrap an element intended for displaying a tooltip.
1314
* This tooltip would show immediately without user's interaction and hide after 5 seconds.
1415
*/
15-
function BaseEducationalTooltip({children, onHideTooltip, shouldAutoDismiss = false, ...props}: EducationalTooltipProps) {
16+
function BaseEducationalTooltip({children, onHideTooltip, shouldRender = false, shouldAutoDismiss = false, ...props}: EducationalTooltipProps) {
1617
const hideTooltipRef = useRef<() => void>();
1718

1819
const [shouldMeasure, setShouldMeasure] = useState(false);
1920
const show = useRef<() => void>();
20-
const [modal] = useOnyx(ONYXKEYS.MODAL);
21+
const [modal, setModal] = useState<Modal>({
22+
willAlertModalBecomeVisible: false,
23+
isVisible: false,
24+
});
2125

22-
const shouldShow = !modal?.willAlertModalBecomeVisible && !modal?.isVisible;
26+
const shouldShow = !modal?.willAlertModalBecomeVisible && !modal?.isVisible && shouldRender;
27+
28+
useEffect(() => {
29+
if (!shouldRender) {
30+
return;
31+
}
32+
const unsubscribeOnyxModal = onyxSubscribe({
33+
key: ONYXKEYS.MODAL,
34+
callback: (modalArg) => {
35+
if (modalArg === undefined) {
36+
return;
37+
}
38+
setModal(modalArg);
39+
},
40+
});
41+
return () => {
42+
unsubscribeOnyxModal();
43+
};
44+
}, [shouldRender]);
45+
46+
const didShow = useRef(false);
47+
48+
const closeTooltip = useCallback(() => {
49+
if (!didShow.current) {
50+
return;
51+
}
52+
hideTooltipRef.current?.();
53+
onHideTooltip?.();
54+
}, [onHideTooltip]);
2355

2456
useEffect(
2557
() => () => {
@@ -34,36 +66,45 @@ function BaseEducationalTooltip({children, onHideTooltip, shouldAutoDismiss = fa
3466

3567
// Automatically hide tooltip after 5 seconds
3668
useEffect(() => {
37-
if (!hideTooltipRef.current || !shouldAutoDismiss) {
69+
if (!shouldAutoDismiss) {
3870
return;
3971
}
4072

4173
// If the modal is open, hide the tooltip immediately and clear the timeout
4274
if (!shouldShow) {
43-
hideTooltipRef.current();
75+
closeTooltip();
4476
return;
4577
}
4678

4779
// Automatically hide tooltip after 5 seconds if shouldAutoDismiss is true
4880
const timerID = setTimeout(() => {
49-
hideTooltipRef.current?.();
50-
onHideTooltip?.();
81+
closeTooltip();
5182
}, 5000);
5283
return () => {
5384
clearTimeout(timerID);
5485
};
55-
}, [shouldAutoDismiss, shouldShow, onHideTooltip]);
86+
}, [shouldAutoDismiss, shouldShow, closeTooltip]);
5687

5788
useEffect(() => {
58-
if (!shouldMeasure || !shouldShow) {
89+
if (!shouldMeasure || !shouldShow || didShow.current) {
5990
return;
6091
}
6192
// When tooltip is used inside an animated view (e.g. popover), we need to wait for the animation to finish before measuring content.
62-
setTimeout(() => {
93+
const timerID = setTimeout(() => {
6394
show.current?.();
95+
didShow.current = true;
6496
}, 500);
97+
return () => {
98+
clearTimeout(timerID);
99+
};
65100
}, [shouldMeasure, shouldShow]);
66101

102+
useEffect(
103+
() => closeTooltip,
104+
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
105+
[],
106+
);
107+
67108
return (
68109
<GenericTooltip
69110
shouldForceAnimate

src/components/Tooltip/EducationalTooltip/index.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import React from 'react';
22
import type {TooltipExtendedProps} from '@components/Tooltip/types';
33
import BaseEducationalTooltip from './BaseEducationalTooltip';
44

5-
function EducationalTooltip({children, shouldRender = false, ...props}: TooltipExtendedProps) {
6-
if (!shouldRender) {
7-
return children;
8-
}
9-
5+
function EducationalTooltip({children, ...props}: TooltipExtendedProps) {
106
return (
117
<BaseEducationalTooltip
128
// eslint-disable-next-line react/jsx-props-no-spreading

src/pages/Search/SearchTypeMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function SearchTypeMenu({queryJSON, searchName}: SearchTypeMenuProps) {
151151
tooltipShiftHorizontal: -32,
152152
tooltipShiftVertical: 15,
153153
tooltipWrapperStyle: [styles.bgPaleGreen, styles.mh4, styles.pv2],
154-
onHideTooltip: () => SearchActions.dismissSavedSearchRenameTooltip(),
154+
onHideTooltip: SearchActions.dismissSavedSearchRenameTooltip,
155155
renderTooltipContent: () => {
156156
return (
157157
<View style={[styles.flexRow, styles.alignItemsCenter]}>

src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ function ReportActionCompose({
408408
shouldRender={!shouldHideEducationalTooltip && shouldShowEducationalTooltip}
409409
renderTooltipContent={renderWorkspaceChatTooltip}
410410
shouldUseOverlay
411-
onHideTooltip={() => User.dismissWorkspaceTooltip()}
411+
onHideTooltip={User.dismissWorkspaceTooltip}
412412
anchorAlignment={{
413413
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
414414
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,

0 commit comments

Comments
 (0)