Skip to content

Commit 94761ec

Browse files
committed
fix : Failed to measure target component after multiple retries.
1 parent d1338da commit 94761ec

File tree

1 file changed

+18
-47
lines changed

1 file changed

+18
-47
lines changed

src/HighLightToolTip.tsx

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -52,57 +52,28 @@ export const HighlightToolTip: React.FC<HighlightOverlayProps> = ({
5252
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
5353

5454
useEffect(() => {
55-
const measure = (retryCount = 0) => {
56-
if (!targetRef.current) {
57-
if (retryCount < 5) {
58-
setTimeout(() => measure(retryCount + 1), 100);
59-
}
60-
return;
61-
}
62-
const handle = findNodeHandle(targetRef.current);
63-
if (handle) {
64-
UIManager.measureInWindow(handle, (x, y, width, height) => {
65-
if (
66-
[x, y, width, height].some(
67-
(val) => typeof val !== 'number' || isNaN(val)
68-
) ||
69-
(width === 0 && height === 0)
70-
) {
71-
if (retryCount < 5) {
72-
setTimeout(() => measure(retryCount + 1), 100);
73-
} else {
74-
console.warn(
75-
'HighlightToolTip: Failed to measure target component after multiple retries.'
76-
);
77-
onRequestClose();
55+
const task = InteractionManager.runAfterInteractions(() => {
56+
if (targetRef.current) {
57+
const handle = findNodeHandle(targetRef.current);
58+
if (handle) {
59+
UIManager.measureInWindow(
60+
handle,
61+
(x: number, y: number, width: number, height: number) => {
62+
const isAndroid = Platform.OS === 'android';
63+
setHole({
64+
x,
65+
y: isAndroid ? y + androidOffsetY : y,
66+
width,
67+
height,
68+
});
7869
}
79-
return;
80-
}
81-
82-
const isAndroid = Platform.OS === 'android';
83-
setHole({
84-
x,
85-
y: isAndroid ? y + androidOffsetY : y,
86-
width,
87-
height,
88-
});
89-
});
90-
} else if (retryCount < 5) {
91-
setTimeout(() => measure(retryCount + 1), 100);
92-
} else {
93-
console.warn(
94-
'HighlightToolTip: Could not find node handle for targetRef after multiple retries.'
95-
);
96-
onRequestClose();
70+
);
71+
}
9772
}
98-
};
99-
100-
const interactionHandle = InteractionManager.runAfterInteractions(() => {
101-
measure();
10273
});
10374

104-
return () => interactionHandle.cancel();
105-
}, [targetRef, androidOffsetY, onRequestClose]);
75+
return () => task.cancel();
76+
}, [targetRef, androidOffsetY]);
10677

10778
const onTooltipLayout = (event: LayoutChangeEvent) => {
10879
const { width, height } = event.nativeEvent.layout;

0 commit comments

Comments
 (0)