@momo-kits/animated-tooltip 0.167.1-duotest.1 → 0.167.1-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/helpers.ts ADDED
@@ -0,0 +1,141 @@
1
+ import { ViewStyle } from 'react-native';
2
+ import { Colors, Spacing } from '@momo-kits/foundation';
3
+ import styles from './styles';
4
+ import { TooltipPlacement, TooltipProps } from './types';
5
+
6
+ type Align = NonNullable<TooltipProps['align']>;
7
+
8
+ export const getPlacementStyle = ({
9
+ anchorPosition,
10
+ tooltipSize,
11
+ placement,
12
+ align,
13
+ hostX,
14
+ hostY,
15
+ offset,
16
+ }: {
17
+ anchorPosition: { x: number; y: number; width: number; height: number };
18
+ tooltipSize: { width: number; height: number };
19
+ placement: TooltipPlacement;
20
+ align: Align;
21
+ hostX: number;
22
+ hostY: number;
23
+ offset: number;
24
+ }): {
25
+ top?: number;
26
+ left?: number;
27
+ right?: number;
28
+ bottom?: number;
29
+ } => {
30
+ const { x, y, width, height } = anchorPosition;
31
+ const { width: tooltipWidth, height: tooltipHeight } = tooltipSize;
32
+
33
+ let position: { top?: number; left?: number; right?: number } = {};
34
+
35
+ // Vertical positioning (relative to portal host)
36
+ if (placement === 'top') {
37
+ position.top = y - tooltipHeight - offset - hostY;
38
+ } else if (placement === 'bottom') {
39
+ position.top = y + height + offset - hostY;
40
+ } else {
41
+ // For left/right placement, calculate vertical center alignment
42
+ if (align === 'start') {
43
+ position.top = y - hostY;
44
+ } else if (align === 'end') {
45
+ position.top = y + height - tooltipHeight - hostY;
46
+ } else {
47
+ // center
48
+ position.top = y + height / 2 - tooltipHeight / 2 - hostY;
49
+ }
50
+ }
51
+
52
+ // Horizontal positioning (relative to portal host)
53
+ if (placement === 'left') {
54
+ position.left = x - tooltipWidth - offset - hostX;
55
+ } else if (placement === 'right') {
56
+ position.left = x + width + offset - hostX;
57
+ } else {
58
+ // For top/bottom placement, calculate horizontal alignment
59
+ if (align === 'start') {
60
+ position.left = x - hostX;
61
+ } else if (align === 'end') {
62
+ position.left = x + width - tooltipWidth - hostX;
63
+ } else {
64
+ // center
65
+ position.left = x + width / 2 - tooltipWidth / 2 - hostX;
66
+ }
67
+ }
68
+
69
+ return position;
70
+ };
71
+
72
+ export const getTooltipArrowStyle = ({
73
+ arrowSize,
74
+ align,
75
+ placement,
76
+ tooltipSize,
77
+ }: {
78
+ arrowSize: number;
79
+ align: Align;
80
+ placement: TooltipPlacement;
81
+ tooltipSize: { width: number; height: number };
82
+ }): object[] => {
83
+ const size = arrowSize;
84
+ const common = [
85
+ styles.arrow,
86
+ {
87
+ width: size * 2,
88
+ height: size * 2,
89
+ backgroundColor: Colors.black_17,
90
+ transform: [{ rotate: '45deg' }],
91
+ borderRadius: size / 2,
92
+ },
93
+ ];
94
+ const inset = size + Spacing.M;
95
+ const centerTop = (tooltipSize.height || 0) / 2 - size;
96
+ let horizontalAlign: ViewStyle = { alignSelf: 'center' };
97
+ let verticalAlign: ViewStyle = { top: centerTop };
98
+ if (align === 'start') {
99
+ horizontalAlign = { left: inset };
100
+ verticalAlign = { top: inset };
101
+ } else if (align === 'end') {
102
+ horizontalAlign = { right: inset };
103
+ verticalAlign = { bottom: inset };
104
+ }
105
+
106
+ switch (placement) {
107
+ case 'top':
108
+ return [
109
+ ...common,
110
+ {
111
+ bottom: -(size - 1),
112
+ ...horizontalAlign,
113
+ },
114
+ ];
115
+ case 'bottom':
116
+ return [
117
+ ...common,
118
+ {
119
+ top: -(size - 1),
120
+ ...horizontalAlign,
121
+ },
122
+ ];
123
+ case 'left':
124
+ return [
125
+ ...common,
126
+ {
127
+ right: -(size - 1),
128
+ ...verticalAlign,
129
+ },
130
+ ];
131
+ case 'right':
132
+ default:
133
+ return [
134
+ ...common,
135
+ {
136
+ left: -(size - 1),
137
+ ...verticalAlign,
138
+ },
139
+ ];
140
+ }
141
+ };
package/index.tsx CHANGED
@@ -11,23 +11,21 @@ import React, {
11
11
  import {
12
12
  Animated,
13
13
  Easing,
14
- TouchableOpacity,
15
14
  TouchableWithoutFeedback,
16
15
  useWindowDimensions,
17
16
  View,
18
17
  } from 'react-native';
19
18
  import {
20
- Colors,
21
- Icon,
22
19
  MiniAppContext,
23
20
  ScreenContext,
24
21
  Spacing,
25
- Text,
26
22
  useTooltipPortal,
27
23
  } from '@momo-kits/foundation';
28
24
  import styles from './styles';
29
25
  import { TooltipPlacement, TooltipProps, TooltipRef } from './types';
30
- import { IconButton, PrimaryButton, SecondaryButton } from './TooltipButtons';
26
+ import { usePreloadMeasure } from './usePreloadMeasure';
27
+ import { getPlacementStyle, getTooltipArrowStyle } from './helpers';
28
+ import { renderTooltipContent } from './renderButtons';
31
29
 
32
30
  const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
33
31
  {
@@ -127,26 +125,12 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
127
125
  animate(visibleRef.current);
128
126
  }, [tooltipSize, animate]);
129
127
 
130
- // Preload anchor measurement on mount for faster initial display
131
- useEffect(() => {
132
- // Measure immediately on mount to have position ready
133
- const timer = setTimeout(() => {
134
- // Measure host position first
135
- if (portal.hostRef?.current) {
136
- portal.hostRef.current.measureInWindow((hostX, hostY) => {
137
- setHostPosition({ x: hostX, y: hostY });
138
- });
139
- }
140
-
141
- anchorRef.current?.measureInWindow((x, y, width, height) => {
142
- if (x !== 0 || y !== 0 || width !== 0 || height !== 0) {
143
- setAnchorPosition({ x, y, width, height });
144
- }
145
- });
146
- }, 0);
147
-
148
- return () => clearTimeout(timer);
149
- }, [portal.hostRef]);
128
+ usePreloadMeasure({
129
+ hostRef: portal.hostRef,
130
+ anchorRef,
131
+ setHostPosition,
132
+ setAnchorPosition,
133
+ });
150
134
 
151
135
  useEffect(() => {
152
136
  if (!visibleRef.current) {
@@ -255,278 +239,39 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
255
239
  [handleHide, handleShow],
256
240
  );
257
241
 
258
- const translate =
259
- placement === 'top'
260
- ? {
261
- translateY: animatedValue.interpolate({
262
- inputRange: [0, 1],
263
- outputRange: [4, 0],
264
- }),
265
- }
266
- : placement === 'bottom'
267
- ? {
268
- translateY: animatedValue.interpolate({
269
- inputRange: [0, 1],
270
- outputRange: [-4, 0],
271
- }),
272
- }
273
- : placement === 'left'
274
- ? {
275
- translateX: animatedValue.interpolate({
276
- inputRange: [0, 1],
277
- outputRange: [4, 0],
278
- }),
279
- }
280
- : {
281
- translateX: animatedValue.interpolate({
282
- inputRange: [0, 1],
283
- outputRange: [-4, 0],
284
- }),
285
- };
286
-
287
- const placementStyle = useMemo((): {
288
- top?: number;
289
- left?: number;
290
- right?: number;
291
- bottom?: number;
292
- } => {
293
- const { x, y, width, height } = anchorPosition;
294
- const { width: tooltipWidth, height: tooltipHeight } = tooltipSize;
295
-
296
- let position: { top?: number; left?: number; right?: number } = {};
297
-
298
- // Vertical positioning (relative to portal host)
299
- if (placement === 'top') {
300
- position.top = y - tooltipHeight - TOOLTIP_OFFSET - hostPosition.y;
301
- } else if (placement === 'bottom') {
302
- position.top = y + height + TOOLTIP_OFFSET - hostPosition.y;
303
- } else {
304
- // For left/right placement, calculate vertical center alignment
305
- if (align === 'start') {
306
- position.top = y - hostPosition.y;
307
- } else if (align === 'end') {
308
- position.top = y + height - tooltipHeight - hostPosition.y;
309
- } else {
310
- // center
311
- position.top = y + height / 2 - tooltipHeight / 2 - hostPosition.y;
312
- }
313
- }
314
-
315
- // Horizontal positioning (relative to portal host)
316
- if (placement === 'left') {
317
- position.left = x - tooltipWidth - TOOLTIP_OFFSET - hostPosition.x;
318
- } else if (placement === 'right') {
319
- position.left = x + width + TOOLTIP_OFFSET - hostPosition.x;
320
- } else {
321
- // For top/bottom placement, calculate horizontal alignment
322
- if (align === 'start') {
323
- position.left = x - hostPosition.x;
324
- } else if (align === 'end') {
325
- position.left = x + width - tooltipWidth - hostPosition.x;
326
- } else {
327
- // center
328
- position.left = x + width / 2 - tooltipWidth / 2 - hostPosition.x;
329
- }
330
- }
331
-
332
- return position;
333
- }, [anchorPosition, tooltipSize, placement, TOOLTIP_OFFSET, hostPosition.y, hostPosition.x, align]);
334
-
335
- const renderButtons = () => {
336
- if (!buttons.length) {
337
- return null;
338
- }
339
-
340
- if (buttons.length === 1) {
341
- const btn = buttons[0];
342
- const onPress = btn.onPress ?? (() => { });
343
- return (
344
- <View style={styles.buttonsRow}>
345
- <View
346
- style={[
347
- styles.button,
348
- btn.icon ? styles.iconButton : styles.textButton,
349
- ]}
350
- >
351
- {btn.icon ? (
352
- <IconButton icon={btn.icon} onPress={onPress} />
353
- ) : (
354
- <PrimaryButton title={btn.title || ''} onPress={onPress} />
355
- )}
356
- </View>
357
- </View>
358
- );
359
- }
360
-
361
- if (buttons.length === 2) {
362
- const [first, second] = buttons;
363
- const firstPress = first.onPress ?? (() => { });
364
- const secondPress = second.onPress ?? (() => { });
365
- const bothIcon = !!first.icon && !!second.icon;
366
-
367
- return (
368
- <View style={styles.buttonsRow}>
369
- {bothIcon ? (
370
- <View style={styles.buttonRowContainer}>
371
- <IconButton
372
- icon={second.icon as string}
373
- onPress={secondPress}
374
- style={styles.buttonSpacing}
375
- />
376
- <IconButton icon={first.icon as string} onPress={firstPress} />
377
- </View>
378
- ) : (
379
- <View style={styles.buttonRowContainer}>
380
- <SecondaryButton
381
- title={second.title || ''}
382
- onPress={secondPress}
383
- style={styles.buttonSpacing}
384
- />
385
- <PrimaryButton title={first.title || ''} onPress={firstPress} />
386
- </View>
387
- )}
388
- </View>
389
- );
390
- }
391
-
392
- return (
393
- <View style={styles.buttonsRow}>
394
- {buttons.map((btn, idx) => {
395
- const isIcon = !!btn.icon;
396
- const key = btn.title || btn.icon || `${idx}`;
397
- const onPress = btn.onPress ?? (() => { });
398
-
399
- return (
400
- <View
401
- key={key}
402
- style={[
403
- styles.button,
404
- isIcon ? styles.iconButton : styles.textButton,
405
- ]}
406
- >
407
- {isIcon ? (
408
- <IconButton icon={btn.icon as string} onPress={onPress} />
409
- ) : (
410
- <PrimaryButton title={btn.title || ''} onPress={onPress} />
411
- )}
412
- </View>
413
- );
414
- })}
415
- </View>
416
- );
417
- };
242
+ const isVertical = placement === 'top' || placement === 'bottom';
243
+ const slideFrom = placement === 'top' || placement === 'left' ? 4 : -4;
244
+ const slide = animatedValue.interpolate({
245
+ inputRange: [0, 1],
246
+ outputRange: [slideFrom, 0],
247
+ });
248
+ const translate = isVertical ? { translateY: slide } : { translateX: slide };
249
+
250
+ const placementStyle = useMemo(
251
+ () =>
252
+ getPlacementStyle({
253
+ anchorPosition,
254
+ tooltipSize,
255
+ placement,
256
+ align,
257
+ hostX: hostPosition.x,
258
+ hostY: hostPosition.y,
259
+ offset: TOOLTIP_OFFSET,
260
+ }),
261
+ [anchorPosition, tooltipSize, placement, TOOLTIP_OFFSET, hostPosition.y, hostPosition.x, align]
262
+ );
418
263
 
419
- const renderContent = () => {
420
- return (
421
- <View style={styles.content}>
422
- <View style={styles.contentHeader}>
423
- <View
424
- style={{
425
- minWidth: 100,
426
- maxWidth: SCREEN_WIDTH - Spacing.M * 2 - 48,
427
- }}
428
- >
429
- {title ? (
430
- <Text
431
- typography={'header_s_semibold'}
432
- color={Colors.black_01}
433
- style={styles.title}
434
- >
435
- {title}
436
- </Text>
437
- ) : null}
438
- {description ? (
439
- <Text
440
- typography={'description_default_regular'}
441
- color={Colors.black_01}
442
- style={styles.description}
443
- >
444
- {description}
445
- </Text>
446
- ) : null}
447
- </View>
448
- <TouchableOpacity
449
- onPress={onPressClose}
450
- hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
451
- style={styles.closeIconSpacing}
452
- >
453
- <Icon
454
- source={'navigation_close'}
455
- size={20}
456
- color={Colors.black_01}
457
- />
458
- </TouchableOpacity>
459
- </View>
460
- {renderButtons()}
461
- </View>
462
- );
463
- };
264
+ const renderContent = () =>
265
+ renderTooltipContent({
266
+ title,
267
+ description,
268
+ buttons,
269
+ screenWidth: SCREEN_WIDTH,
270
+ onPressClose,
271
+ });
464
272
 
465
- const getArrowStyle: () => object[] = () => {
466
- const size = arrowSize;
467
- const common = [
468
- styles.arrow,
469
- {
470
- width: size * 2,
471
- height: size * 2,
472
- backgroundColor: Colors.black_17,
473
- transform: [{ rotate: '45deg' }],
474
- borderRadius: size / 2,
475
- },
476
- ];
477
-
478
- switch (placement) {
479
- case 'top':
480
- return [
481
- ...common,
482
- {
483
- bottom: -(size - 1),
484
- ...(align === 'start'
485
- ? { left: size + Spacing.M }
486
- : align === 'end'
487
- ? { right: size + Spacing.M }
488
- : { alignSelf: 'center' }),
489
- },
490
- ];
491
- case 'bottom':
492
- return [
493
- ...common,
494
- {
495
- top: -(size - 1),
496
- ...(align === 'start'
497
- ? { left: size + Spacing.M }
498
- : align === 'end'
499
- ? { right: size + Spacing.M }
500
- : { alignSelf: 'center' }),
501
- },
502
- ];
503
- case 'left':
504
- return [
505
- ...common,
506
- {
507
- right: -(size - 1),
508
- ...(align === 'start'
509
- ? { top: size + Spacing.M }
510
- : align === 'end'
511
- ? { bottom: size + Spacing.M }
512
- : { top: (tooltipSize.height || 0) / 2 - size }),
513
- },
514
- ];
515
- case 'right':
516
- default:
517
- return [
518
- ...common,
519
- {
520
- left: -(size - 1),
521
- ...(align === 'start'
522
- ? { top: size + Spacing.M }
523
- : align === 'end'
524
- ? { bottom: size + Spacing.M }
525
- : { top: (tooltipSize.height || 0) / 2 - size }),
526
- },
527
- ];
528
- }
529
- };
273
+ const getArrowStyle = () =>
274
+ getTooltipArrowStyle({ arrowSize, align, placement, tooltipSize });
530
275
 
531
276
  useEffect(() => {
532
277
  let isActive = true; // Track if effect is still active
@@ -549,15 +294,7 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
549
294
  const content = (
550
295
  <>
551
296
  <TouchableWithoutFeedback onPress={handleHide}>
552
- <View
553
- style={{
554
- position: 'absolute',
555
- top: -9999,
556
- left: -9999,
557
- right: -9999,
558
- bottom: -9999,
559
- }}
560
- />
297
+ <View style={styles.backdrop} />
561
298
  </TouchableWithoutFeedback>
562
299
 
563
300
  <Animated.View
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
- "name": "@momo-kits/animated-tooltip",
3
- "version": "0.167.1-duotest.1",
4
- "private": false,
5
- "main": "index.tsx",
6
- "dependencies": {},
7
- "peerDependencies": {
8
- "@momo-kits/foundation": "latest",
9
- "react": "*",
10
- "react-native": "*"
11
- },
12
- "license": "MoMo",
13
- "publishConfig": {
14
- "registry": "https://registry.npmjs.org/"
15
- }
16
- }
2
+ "name": "@momo-kits/animated-tooltip",
3
+ "version": "0.167.1-rc.2",
4
+ "private": false,
5
+ "main": "index.tsx",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "@momo-kits/foundation": "latest",
9
+ "react": "*",
10
+ "react-native": "*"
11
+ },
12
+ "license": "MoMo",
13
+ "publishConfig": {
14
+ "registry": "https://registry.npmjs.org/"
15
+ }
16
+ }
@@ -0,0 +1,150 @@
1
+ import React from 'react';
2
+ import { TouchableOpacity, View } from 'react-native';
3
+ import { Colors, Icon, Spacing, Text } from '@momo-kits/foundation';
4
+ import styles from './styles';
5
+ import { TooltipButton } from './types';
6
+ import { IconButton, PrimaryButton, SecondaryButton } from './TooltipButtons';
7
+
8
+ export const renderTooltipButtons = (buttons: TooltipButton[]) => {
9
+ if (!buttons.length) {
10
+ return null;
11
+ }
12
+
13
+ if (buttons.length === 1) {
14
+ const btn = buttons[0];
15
+ const onPress = btn.onPress ?? (() => { });
16
+ return (
17
+ <View style={styles.buttonsRow}>
18
+ <View
19
+ style={[
20
+ styles.button,
21
+ btn.icon ? styles.iconButton : styles.textButton,
22
+ ]}
23
+ >
24
+ {btn.icon ? (
25
+ <IconButton icon={btn.icon} onPress={onPress} />
26
+ ) : (
27
+ <PrimaryButton title={btn.title || ''} onPress={onPress} />
28
+ )}
29
+ </View>
30
+ </View>
31
+ );
32
+ }
33
+
34
+ if (buttons.length === 2) {
35
+ const [first, second] = buttons;
36
+ const firstPress = first.onPress ?? (() => { });
37
+ const secondPress = second.onPress ?? (() => { });
38
+ const bothIcon = !!first.icon && !!second.icon;
39
+
40
+ return (
41
+ <View style={styles.buttonsRow}>
42
+ {bothIcon ? (
43
+ <View style={styles.buttonRowContainer}>
44
+ <IconButton
45
+ icon={second.icon as string}
46
+ onPress={secondPress}
47
+ style={styles.buttonSpacing}
48
+ />
49
+ <IconButton icon={first.icon as string} onPress={firstPress} />
50
+ </View>
51
+ ) : (
52
+ <View style={styles.buttonRowContainer}>
53
+ <SecondaryButton
54
+ title={second.title || ''}
55
+ onPress={secondPress}
56
+ style={styles.buttonSpacing}
57
+ />
58
+ <PrimaryButton title={first.title || ''} onPress={firstPress} />
59
+ </View>
60
+ )}
61
+ </View>
62
+ );
63
+ }
64
+
65
+ return (
66
+ <View style={styles.buttonsRow}>
67
+ {buttons.map((btn, idx) => {
68
+ const isIcon = !!btn.icon;
69
+ const key = btn.title || btn.icon || `${idx}`;
70
+ const onPress = btn.onPress ?? (() => { });
71
+
72
+ return (
73
+ <View
74
+ key={key}
75
+ style={[
76
+ styles.button,
77
+ isIcon ? styles.iconButton : styles.textButton,
78
+ ]}
79
+ >
80
+ {isIcon ? (
81
+ <IconButton icon={btn.icon as string} onPress={onPress} />
82
+ ) : (
83
+ <PrimaryButton title={btn.title || ''} onPress={onPress} />
84
+ )}
85
+ </View>
86
+ );
87
+ })}
88
+ </View>
89
+ );
90
+ };
91
+
92
+ export const renderTooltipContent = ({
93
+ title,
94
+ description,
95
+ buttons,
96
+ screenWidth,
97
+ onPressClose,
98
+ }: {
99
+ title?: string;
100
+ description?: string;
101
+ buttons: TooltipButton[];
102
+ screenWidth: number;
103
+ onPressClose?: () => void;
104
+ }) => {
105
+ return (
106
+ <View style={styles.content}>
107
+ <View style={styles.contentHeader}>
108
+ <View
109
+ style={[
110
+ styles.contentTextContainer,
111
+ {
112
+ maxWidth: screenWidth - Spacing.M * 2 - 48,
113
+ },
114
+ ]}
115
+ >
116
+ {title ? (
117
+ <Text
118
+ typography={'header_s_semibold'}
119
+ color={Colors.black_01}
120
+ style={styles.title}
121
+ >
122
+ {title}
123
+ </Text>
124
+ ) : null}
125
+ {description ? (
126
+ <Text
127
+ typography={'description_default_regular'}
128
+ color={Colors.black_01}
129
+ style={styles.description}
130
+ >
131
+ {description}
132
+ </Text>
133
+ ) : null}
134
+ </View>
135
+ <TouchableOpacity
136
+ onPress={onPressClose}
137
+ hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
138
+ style={styles.closeIconSpacing}
139
+ >
140
+ <Icon
141
+ source={'navigation_close'}
142
+ size={20}
143
+ color={Colors.black_01}
144
+ />
145
+ </TouchableOpacity>
146
+ </View>
147
+ {renderTooltipButtons(buttons)}
148
+ </View>
149
+ );
150
+ };
package/styles.ts CHANGED
@@ -67,4 +67,14 @@ export default StyleSheet.create({
67
67
  anchorView: {
68
68
  alignSelf: 'flex-start',
69
69
  },
70
+ contentTextContainer: {
71
+ minWidth: 100,
72
+ },
73
+ backdrop: {
74
+ position: 'absolute',
75
+ top: -9999,
76
+ left: -9999,
77
+ right: -9999,
78
+ bottom: -9999,
79
+ },
70
80
  });
@@ -0,0 +1,37 @@
1
+ import { RefObject, useEffect } from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ type Position = { x: number; y: number; width: number; height: number };
5
+
6
+ export const usePreloadMeasure = ({
7
+ hostRef,
8
+ anchorRef,
9
+ setHostPosition,
10
+ setAnchorPosition,
11
+ }: {
12
+ hostRef?: RefObject<View | null> | null;
13
+ anchorRef: RefObject<View | null>;
14
+ setHostPosition: (position: { x: number; y: number }) => void;
15
+ setAnchorPosition: (position: Position) => void;
16
+ }) => {
17
+ // Preload anchor measurement on mount for faster initial display
18
+ useEffect(() => {
19
+ // Measure immediately on mount to have position ready
20
+ const timer = setTimeout(() => {
21
+ // Measure host position first
22
+ if (hostRef?.current) {
23
+ hostRef.current.measureInWindow((hostX, hostY) => {
24
+ setHostPosition({ x: hostX, y: hostY });
25
+ });
26
+ }
27
+
28
+ anchorRef.current?.measureInWindow((x, y, width, height) => {
29
+ if (x !== 0 || y !== 0 || width !== 0 || height !== 0) {
30
+ setAnchorPosition({ x, y, width, height });
31
+ }
32
+ });
33
+ }, 0);
34
+
35
+ return () => clearTimeout(timer);
36
+ }, [hostRef, anchorRef, setHostPosition, setAnchorPosition]);
37
+ };