({
children,
enterTouchDelay = 500,
leaveTouchDelay = 1500,
title,
theme: themeOverrides,
titleMaxFontSizeMultiplier,
...rest
}: Props)
| 64 | * ``` |
| 65 | */ |
| 66 | const Tooltip = ({ |
| 67 | children, |
| 68 | enterTouchDelay = 500, |
| 69 | leaveTouchDelay = 1500, |
| 70 | title, |
| 71 | theme: themeOverrides, |
| 72 | titleMaxFontSizeMultiplier, |
| 73 | ...rest |
| 74 | }: Props) => { |
| 75 | const isWeb = Platform.OS === 'web'; |
| 76 | |
| 77 | const theme = useInternalTheme(themeOverrides); |
| 78 | const [visible, setVisible] = React.useState(false); |
| 79 | |
| 80 | const [measurement, setMeasurement] = React.useState({ |
| 81 | children: {}, |
| 82 | tooltip: {}, |
| 83 | measured: false, |
| 84 | }); |
| 85 | const showTooltipTimer = React.useRef<NodeJS.Timeout[]>([]); |
| 86 | const hideTooltipTimer = React.useRef<NodeJS.Timeout[]>([]); |
| 87 | |
| 88 | const childrenWrapperRef = React.useRef<View>(null); |
| 89 | const touched = React.useRef(false); |
| 90 | |
| 91 | const isValidChild = React.useMemo( |
| 92 | () => React.isValidElement<TooltipChildProps>(children), |
| 93 | [children] |
| 94 | ); |
| 95 | |
| 96 | React.useEffect(() => { |
| 97 | return () => { |
| 98 | if (showTooltipTimer.current.length) { |
| 99 | showTooltipTimer.current.forEach((t) => clearTimeout(t)); |
| 100 | showTooltipTimer.current = []; |
| 101 | } |
| 102 | |
| 103 | if (hideTooltipTimer.current.length) { |
| 104 | hideTooltipTimer.current.forEach((t) => clearTimeout(t)); |
| 105 | hideTooltipTimer.current = []; |
| 106 | } |
| 107 | }; |
| 108 | }, []); |
| 109 | |
| 110 | React.useEffect(() => { |
| 111 | const subscription = addEventListener(Dimensions, 'change', () => |
| 112 | setVisible(false) |
| 113 | ); |
| 114 | |
| 115 | return () => subscription.remove(); |
| 116 | }, []); |
| 117 | |
| 118 | const handleTouchStart = React.useCallback(() => { |
| 119 | if (hideTooltipTimer.current.length) { |
| 120 | hideTooltipTimer.current.forEach((t) => clearTimeout(t)); |
| 121 | hideTooltipTimer.current = []; |
| 122 | } |
| 123 |
nothing calls this directly
no test coverage detected
searching dependent graphs…