Skip to content

Commit 575553a

Browse files
refactor: extract useLHNRowProductTrainingTooltip, drop onPressBefore prop
1 parent 6215b44 commit 575553a

4 files changed

Lines changed: 41 additions & 29 deletions

File tree

src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ function OptionRowLHN({
111111
contextMenuHint,
112112
});
113113

114-
const renderPressableRow = (onPressBefore?: () => void) => (
114+
const renderPressableRow = () => (
115115
<OptionRowPressable
116116
reportID={reportID}
117117
optionItem={optionItem}
118118
isOptionFocused={isOptionFocused}
119119
isScreenFocused={isScreenFocused}
120120
popoverAnchor={popoverAnchor}
121121
onSelectRow={onSelectRow}
122-
onPressBefore={onPressBefore}
123122
onLayout={onLayout}
124123
accessibilityLabel={accessibilityLabelWithContextMenuHint}
125124
accessibilityHint={accessibilityHint}

src/components/LHNOptionsList/OptionRowLHN/OptionRowPressable.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {startSpan} from '@libs/telemetry/activeSpans';
1414
import {showContextMenu} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
1515
import variables from '@styles/variables';
1616
import CONST from '@src/CONST';
17+
import useLHNRowProductTrainingTooltip from './useLHNRowProductTrainingTooltip';
1718

1819
type OptionRowPressableProps = {
1920
reportID: string;
@@ -22,8 +23,6 @@ type OptionRowPressableProps = {
2223
isScreenFocused: boolean;
2324
popoverAnchor: RefObject<View | null>;
2425
onSelectRow: (optionItem: OptionData, popoverAnchor: RefObject<View | null>) => void;
25-
/** Optional hook fired before the row press (e.g. hide product training tooltip). */
26-
onPressBefore?: () => void;
2726
onLayout?: (event: LayoutChangeEvent) => void;
2827
accessibilityLabel: string;
2928
accessibilityHint?: string;
@@ -38,15 +37,15 @@ function OptionRowPressable({
3837
isScreenFocused,
3938
popoverAnchor,
4039
onSelectRow,
41-
onPressBefore,
4240
onLayout,
4341
accessibilityLabel,
4442
accessibilityHint,
4543
testID,
4644
children,
4745
}: OptionRowPressableProps) {
46+
const {hideProductTrainingTooltip} = useLHNRowProductTrainingTooltip();
4847
const onPress = (event: GestureResponderEvent | KeyboardEvent | undefined) => {
49-
onPressBefore?.();
48+
hideProductTrainingTooltip();
5049
startSpan(`${CONST.TELEMETRY.SPAN_OPEN_REPORT}_${reportID}`, {
5150
name: 'OptionRowLHN',
5251
op: CONST.TELEMETRY.SPAN_OPEN_REPORT,

src/components/LHNOptionsList/OptionRowLHN/OptionRowTooltipLayer.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import React, {useMemo} from 'react';
1+
import React from 'react';
22
import type {OnyxEntry} from 'react-native-onyx';
33
import {useLHNTooltipContext} from '@components/LHNOptionsList/LHNTooltipContext';
44
import OfflineWithFeedback from '@components/OfflineWithFeedback';
55
import {useSession} from '@components/OnyxListItemProvider';
6-
import {useProductTrainingContext} from '@components/ProductTrainingContext';
76
import EducationalTooltip from '@components/Tooltip/EducationalTooltip';
87
import useOnyx from '@hooks/useOnyx';
9-
import useResponsiveLayout from '@hooks/useResponsiveLayout';
108
import useThemeStyles from '@hooks/useThemeStyles';
119
import {isAdminRoom, isChatUsedForOnboarding as isChatUsedForOnboardingReportUtils, isConciergeChatReport} from '@libs/ReportUtils';
1210
import type {OptionData} from '@libs/ReportUtils';
1311
import variables from '@styles/variables';
1412
import CONST from '@src/CONST';
1513
import ONYXKEYS from '@src/ONYXKEYS';
1614
import type {Report} from '@src/types/onyx';
15+
import useLHNRowProductTrainingTooltip from './useLHNRowProductTrainingTooltip';
1716

1817
type OptionRowTooltipLayerProps = {
1918
/** Report ID of the row */
@@ -25,32 +24,17 @@ type OptionRowTooltipLayerProps = {
2524
/** Option data, used to forward pendingAction and errors to OfflineWithFeedback */
2625
optionItem: OptionData;
2726

28-
/** Renders the row content. Receives an optional `onPressBefore` callback (tooltip hide) to compose with row press. */
29-
renderChildren: (onPressBefore?: () => void) => React.ReactNode;
27+
/** Renders the row content. */
28+
renderChildren: () => React.ReactNode;
3029
};
3130

3231
type OptionRowTooltipLayerInnerProps = {
33-
renderChildren: (onPressBefore?: () => void) => React.ReactNode;
32+
renderChildren: () => React.ReactNode;
3433
};
3534

3635
function OptionRowTooltipLayerInner({renderChildren}: OptionRowTooltipLayerInnerProps) {
3736
const styles = useThemeStyles();
38-
const {shouldUseNarrowLayout} = useResponsiveLayout();
39-
const {isFullscreenVisible, isScreenFocused, isReportsSplitNavigatorLast} = useLHNTooltipContext();
40-
41-
const {tooltipToRender, shouldShowTooltip} = useMemo(() => {
42-
// TODO: CONCIERGE_LHN_GBR tooltip will be replaced by a tooltip in the #admins room
43-
// https://github.com/Expensify/App/issues/57045#issuecomment-2701455668
44-
const tooltip = CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.CONCIERGE_LHN_GBR;
45-
const shouldTooltipBeVisible = shouldUseNarrowLayout ? isScreenFocused && isReportsSplitNavigatorLast : isReportsSplitNavigatorLast && !isFullscreenVisible;
46-
47-
return {
48-
tooltipToRender: tooltip,
49-
shouldShowTooltip: shouldTooltipBeVisible,
50-
};
51-
}, [isScreenFocused, shouldUseNarrowLayout, isReportsSplitNavigatorLast, isFullscreenVisible]);
52-
53-
const {shouldShowProductTrainingTooltip, renderProductTrainingTooltip, hideProductTrainingTooltip} = useProductTrainingContext(tooltipToRender, shouldShowTooltip);
37+
const {shouldShowProductTrainingTooltip, renderProductTrainingTooltip, hideProductTrainingTooltip} = useLHNRowProductTrainingTooltip();
5438

5539
return (
5640
<EducationalTooltip
@@ -66,7 +50,7 @@ function OptionRowTooltipLayerInner({renderChildren}: OptionRowTooltipLayerInner
6650
onTooltipPress={hideProductTrainingTooltip}
6751
shouldHideOnScroll
6852
>
69-
{renderChildren(hideProductTrainingTooltip)}
53+
{renderChildren()}
7054
</EducationalTooltip>
7155
);
7256
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {useMemo} from 'react';
2+
import {useLHNTooltipContext} from '@components/LHNOptionsList/LHNTooltipContext';
3+
import {useProductTrainingContext} from '@components/ProductTrainingContext';
4+
import useResponsiveLayout from '@hooks/useResponsiveLayout';
5+
import CONST from '@src/CONST';
6+
7+
/**
8+
* Resolves the product-training tooltip state (CONCIERGE_LHN_GBR) for an LHN row.
9+
* Used by both OptionRowTooltipLayerInner (render the tooltip) and OptionRowPressable (hide on press).
10+
*/
11+
function useLHNRowProductTrainingTooltip() {
12+
const {shouldUseNarrowLayout} = useResponsiveLayout();
13+
const {isFullscreenVisible, isScreenFocused, isReportsSplitNavigatorLast} = useLHNTooltipContext();
14+
15+
const {tooltipToRender, shouldShowTooltip} = useMemo(() => {
16+
// TODO: CONCIERGE_LHN_GBR tooltip will be replaced by a tooltip in the #admins room
17+
// https://github.com/Expensify/App/issues/57045#issuecomment-2701455668
18+
const tooltip = CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.CONCIERGE_LHN_GBR;
19+
const shouldTooltipBeVisible = shouldUseNarrowLayout ? isScreenFocused && isReportsSplitNavigatorLast : isReportsSplitNavigatorLast && !isFullscreenVisible;
20+
21+
return {
22+
tooltipToRender: tooltip,
23+
shouldShowTooltip: shouldTooltipBeVisible,
24+
};
25+
}, [isScreenFocused, shouldUseNarrowLayout, isReportsSplitNavigatorLast, isFullscreenVisible]);
26+
27+
return useProductTrainingContext(tooltipToRender, shouldShowTooltip);
28+
}
29+
30+
export default useLHNRowProductTrainingTooltip;

0 commit comments

Comments
 (0)