MCPcopy
hub / github.com/callstack/react-native-paper / Tooltip

Function Tooltip

src/components/Tooltip/Tooltip.tsx:66–245  ·  view source on GitHub ↗
({
  children,
  enterTouchDelay = 500,
  leaveTouchDelay = 1500,
  title,
  theme: themeOverrides,
  titleMaxFontSizeMultiplier,
  ...rest
}: Props)

Source from the content-addressed store, hash-verified

64 * ```
65 */
66const 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

Callers

nothing calls this directly

Calls 5

useInternalThemeFunction · 0.90
addEventListenerFunction · 0.90
getTooltipPositionFunction · 0.90
removeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…