@@ -3,6 +3,7 @@ import React, {useState} from 'react';
33import { Animated } from 'react-native' ;
44import PressableWithFeedback from '@components/Pressable/PressableWithFeedback' ;
55import Tooltip from '@components/Tooltip' ;
6+ import EducationalTooltip from '@components/Tooltip/EducationalTooltip' ;
67import useThemeStyles from '@hooks/useThemeStyles' ;
78import CONST from '@src/CONST' ;
89import type IconAsset from '@src/types/utils/IconAsset' ;
@@ -38,6 +39,12 @@ type TabSelectorItemProps = {
3839
3940 /** Test identifier used to find elements in unit and e2e tests */
4041 testID ?: string ;
42+
43+ /** Determines whether the product training tooltip should be displayed to the user. */
44+ shouldShowProductTrainingTooltip ?: boolean ;
45+
46+ /** Function to render the content of the product training tooltip. */
47+ renderProductTrainingTooltip ?: ( ) => React . JSX . Element ;
4148} ;
4249
4350function TabSelectorItem ( {
@@ -50,39 +57,61 @@ function TabSelectorItem({
5057 isActive = false ,
5158 shouldShowLabelWhenInactive = true ,
5259 testID,
60+ shouldShowProductTrainingTooltip = false ,
61+ renderProductTrainingTooltip,
5362} : TabSelectorItemProps ) {
5463 const styles = useThemeStyles ( ) ;
5564 const [ isHovered , setIsHovered ] = useState ( false ) ;
5665
57- return (
58- < Tooltip
59- shouldRender = { ! shouldShowLabelWhenInactive && ! isActive }
60- text = { title }
66+ const shouldShowEducationalTooltip = shouldShowProductTrainingTooltip && isActive ;
67+
68+ const children = (
69+ < AnimatedPressableWithFeedback
70+ accessibilityLabel = { title }
71+ style = { [ styles . tabSelectorButton , styles . tabBackground ( isHovered , isActive , backgroundColor ) , styles . userSelectNone ] }
72+ wrapperStyle = { [ styles . flexGrow1 ] }
73+ onPress = { onPress }
74+ onHoverIn = { ( ) => setIsHovered ( true ) }
75+ onHoverOut = { ( ) => setIsHovered ( false ) }
76+ role = { CONST . ROLE . BUTTON }
77+ dataSet = { { [ CONST . SELECTION_SCRAPER_HIDDEN_ELEMENT ] : true } }
78+ testID = { testID }
6179 >
62- < AnimatedPressableWithFeedback
63- accessibilityLabel = { title }
64- style = { [ styles . tabSelectorButton , styles . tabBackground ( isHovered , isActive , backgroundColor ) , styles . userSelectNone ] }
65- wrapperStyle = { [ styles . flexGrow1 ] }
66- onPress = { onPress }
67- onHoverIn = { ( ) => setIsHovered ( true ) }
68- onHoverOut = { ( ) => setIsHovered ( false ) }
69- role = { CONST . ROLE . BUTTON }
70- dataSet = { { [ CONST . SELECTION_SCRAPER_HIDDEN_ELEMENT ] : true } }
71- testID = { testID }
72- >
73- < TabIcon
74- icon = { icon }
80+ < TabIcon
81+ icon = { icon }
82+ activeOpacity = { styles . tabOpacity ( isHovered , isActive , activeOpacity , inactiveOpacity ) . opacity }
83+ inactiveOpacity = { styles . tabOpacity ( isHovered , isActive , inactiveOpacity , activeOpacity ) . opacity }
84+ />
85+ { ( shouldShowLabelWhenInactive || isActive ) && (
86+ < TabLabel
87+ title = { title }
7588 activeOpacity = { styles . tabOpacity ( isHovered , isActive , activeOpacity , inactiveOpacity ) . opacity }
7689 inactiveOpacity = { styles . tabOpacity ( isHovered , isActive , inactiveOpacity , activeOpacity ) . opacity }
7790 />
78- { ( shouldShowLabelWhenInactive || isActive ) && (
79- < TabLabel
80- title = { title }
81- activeOpacity = { styles . tabOpacity ( isHovered , isActive , activeOpacity , inactiveOpacity ) . opacity }
82- inactiveOpacity = { styles . tabOpacity ( isHovered , isActive , inactiveOpacity , activeOpacity ) . opacity }
83- />
84- ) }
85- </ AnimatedPressableWithFeedback >
91+ ) }
92+ </ AnimatedPressableWithFeedback >
93+ ) ;
94+
95+ return shouldShowEducationalTooltip ? (
96+ < EducationalTooltip
97+ shouldRender
98+ renderTooltipContent = { renderProductTrainingTooltip }
99+ shouldHideOnNavigate
100+ anchorAlignment = { {
101+ horizontal : CONST . MODAL . ANCHOR_ORIGIN_HORIZONTAL . CENTER ,
102+ vertical : CONST . MODAL . ANCHOR_ORIGIN_VERTICAL . TOP ,
103+ } }
104+ wrapperStyle = { styles . productTrainingTooltipWrapper }
105+ computeHorizontalShiftForNative
106+ >
107+ { children }
108+ </ EducationalTooltip >
109+ ) : (
110+ < Tooltip
111+ shouldRender = { ! shouldShowLabelWhenInactive && ! isActive }
112+ text = { title }
113+ >
114+ { children }
86115 </ Tooltip >
87116 ) ;
88117}
0 commit comments