diff --git a/src/components/Tooltip/index.js b/src/components/Tooltip/index.js index 004d27ef969c..398df07649cf 100644 --- a/src/components/Tooltip/index.js +++ b/src/components/Tooltip/index.js @@ -4,13 +4,12 @@ import {Animated} from 'react-native'; import {BoundsObserver} from '@react-ng/bounds-observer'; import TooltipRenderedOnPageBody from './TooltipRenderedOnPageBody'; import Hoverable from '../Hoverable'; -import withWindowDimensions from '../withWindowDimensions'; import * as tooltipPropTypes from './tooltipPropTypes'; import TooltipSense from './TooltipSense'; import * as DeviceCapabilities from '../../libs/DeviceCapabilities'; -import compose from '../../libs/compose'; -import withLocalize from '../withLocalize'; import usePrevious from '../../hooks/usePrevious'; +import useLocalize from '../../hooks/useLocalize'; +import useWindowDimensions from '../../hooks/useWindowDimensions'; const hasHoverSupport = DeviceCapabilities.hasHoverSupport(); @@ -21,6 +20,11 @@ const hasHoverSupport = DeviceCapabilities.hasHoverSupport(); * @returns {ReactNodeLike} */ function Tooltip(props) { + const {children, numberOfLines, maxWidth, text, renderTooltipContent, renderTooltipContentKey} = props; + + const {preferredLocale} = useLocalize(); + const {windowWidth} = useWindowDimensions(); + // Is tooltip already rendered on the page's body? happens once. const [isRendered, setIsRendered] = useState(false); // Is the tooltip currently visible? @@ -37,7 +41,7 @@ function Tooltip(props) { const isTooltipSenseInitiator = useRef(false); const animation = useRef(new Animated.Value(0)); const isAnimationCanceled = useRef(false); - const prevText = usePrevious(props.text); + const prevText = usePrevious(text); /** * Display the tooltip in an animation. @@ -72,11 +76,11 @@ function Tooltip(props) { useEffect(() => { // if the tooltip text changed before the initial animation was finished, then the tooltip won't be shown // we need to show the tooltip again - if (isVisible && isAnimationCanceled.current && props.text && prevText !== props.text) { + if (isVisible && isAnimationCanceled.current && text && prevText !== text) { isAnimationCanceled.current = false; showTooltip(); } - }, [isVisible, props.text, prevText, showTooltip]); + }, [isVisible, text, prevText, showTooltip]); /** * Update the tooltip bounding rectangle @@ -118,8 +122,8 @@ function Tooltip(props) { // Skip the tooltip and return the children if the text is empty, // we don't have a render function or the device does not support hovering - if ((_.isEmpty(props.text) && props.renderTooltipContent == null) || !hasHoverSupport) { - return props.children; + if ((_.isEmpty(text) && renderTooltipContent == null) || !hasHoverSupport) { + return children; } return ( @@ -127,20 +131,20 @@ function Tooltip(props) { {isRendered && ( )} - {props.children} + {children} @@ -160,4 +164,4 @@ function Tooltip(props) { Tooltip.propTypes = tooltipPropTypes.propTypes; Tooltip.defaultProps = tooltipPropTypes.defaultProps; -export default compose(withWindowDimensions, withLocalize)(memo(Tooltip)); +export default memo(Tooltip); diff --git a/src/components/Tooltip/tooltipPropTypes.js b/src/components/Tooltip/tooltipPropTypes.js index f9a1847df242..af18c4cfa412 100644 --- a/src/components/Tooltip/tooltipPropTypes.js +++ b/src/components/Tooltip/tooltipPropTypes.js @@ -1,5 +1,4 @@ import PropTypes from 'prop-types'; -import {windowDimensionsPropTypes} from '../withWindowDimensions'; import variables from '../../styles/variables'; import CONST from '../../CONST'; @@ -13,9 +12,6 @@ const propTypes = { /** Children to wrap with Tooltip. */ children: PropTypes.node.isRequired, - /** Props inherited from withWindowDimensions */ - ...windowDimensionsPropTypes, - /** Any additional amount to manually adjust the horizontal position of the tooltip. A positive value shifts the tooltip to the right, and a negative value shifts it to the left. */ shiftHorizontal: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),