@momo-kits/animated-tooltip 0.169.16-beta.14 → 0.169.16-beta.15
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/index.tsx +0 -19
- package/package.json +1 -1
- package/renderButtons.tsx +0 -1
- package/utils.ts +0 -22
package/index.tsx
CHANGED
|
@@ -26,29 +26,20 @@ import { renderTooltipContent } from './renderButtons';
|
|
|
26
26
|
|
|
27
27
|
const ANIMATION_DURATION = 180;
|
|
28
28
|
const SLIDE_DISTANCE = 4;
|
|
29
|
-
// MoMo's RN fork alerts in dev on a raw Modal unless it is flagged as a kit
|
|
30
|
-
// Modal; spread so the untyped prop passes type checks.
|
|
31
29
|
const MODAL_KIT_PROPS = { isModalKit: true };
|
|
32
30
|
|
|
33
|
-
// Caps the settle wait at about one second of frames.
|
|
34
31
|
const MAX_SETTLE_FRAMES = 60;
|
|
35
32
|
|
|
36
33
|
type Frame = { x: number; y: number; width: number; height: number };
|
|
37
34
|
|
|
38
|
-
// Module-level so every Tooltip instance can close the one currently open.
|
|
39
35
|
let closeActiveTooltip: (() => void) | null = null;
|
|
40
36
|
|
|
41
|
-
/** Whether the frame overlaps the window, not sitting on a screen still off it. */
|
|
42
37
|
const isOnScreen = ({ x, y, width, height }: Frame) => {
|
|
43
38
|
const window = Dimensions.get('window');
|
|
44
39
|
const isInX = x + width > 0 && x < window.width;
|
|
45
40
|
return isInX && y + height > 0 && y < window.height;
|
|
46
41
|
};
|
|
47
42
|
|
|
48
|
-
/**
|
|
49
|
-
* Measures the view each frame until two on-screen reads match, so a tooltip
|
|
50
|
-
* shown while its screen still slides in opens at the settled spot.
|
|
51
|
-
*/
|
|
52
43
|
const measureSettled = (
|
|
53
44
|
getView: () => View | null,
|
|
54
45
|
isStale: () => boolean,
|
|
@@ -77,10 +68,6 @@ const measureSettled = (
|
|
|
77
68
|
});
|
|
78
69
|
};
|
|
79
70
|
|
|
80
|
-
/**
|
|
81
|
-
* Wraps children as the anchor and shows a bubble in its own Modal so it
|
|
82
|
-
* draws above headers and sheets. Opened and closed through the ref.
|
|
83
|
-
*/
|
|
84
71
|
const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
85
72
|
{
|
|
86
73
|
children,
|
|
@@ -111,7 +98,6 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
111
98
|
height: 0,
|
|
112
99
|
});
|
|
113
100
|
|
|
114
|
-
// Window origin of the Modal host; null until measured after it lays out.
|
|
115
101
|
const [hostPosition, setHostPosition] = useState<{
|
|
116
102
|
x: number;
|
|
117
103
|
y: number;
|
|
@@ -129,7 +115,6 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
129
115
|
const [isVisible, setIsVisible] = useState(false);
|
|
130
116
|
const isVisibleRef = useRef(false);
|
|
131
117
|
const isMountedRef = useRef(false);
|
|
132
|
-
// Bumped on every hide so a pending anchor measure cannot reopen it.
|
|
133
118
|
const showToken = useRef(0);
|
|
134
119
|
const onVisibleChangeRef = useRef(onVisibleChange);
|
|
135
120
|
onVisibleChangeRef.current = onVisibleChange;
|
|
@@ -163,7 +148,6 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
163
148
|
[animatedValue],
|
|
164
149
|
);
|
|
165
150
|
|
|
166
|
-
/** Hides at once without the fade-out delay; also used to close a sibling. */
|
|
167
151
|
const hideNow = useCallback(() => {
|
|
168
152
|
showToken.current += 1;
|
|
169
153
|
clearHideTimer();
|
|
@@ -176,7 +160,6 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
176
160
|
}
|
|
177
161
|
}, [animatedValue, clearHideTimer, setVisibility]);
|
|
178
162
|
|
|
179
|
-
// Stay invisible until both bubble size and host origin are known.
|
|
180
163
|
const hasSize = tooltipSize.width > 0 || tooltipSize.height > 0;
|
|
181
164
|
const isReady = isVisible && hasSize && hostPosition !== null;
|
|
182
165
|
useEffect(() => {
|
|
@@ -208,13 +191,11 @@ const Tooltip = forwardRef<TooltipRef, TooltipProps>(function Tooltip(
|
|
|
208
191
|
|
|
209
192
|
const isStale = () => !isMountedRef.current || token !== showToken.current;
|
|
210
193
|
|
|
211
|
-
// Show only once the anchor settles so the bubble opens in place.
|
|
212
194
|
measureSettled(
|
|
213
195
|
() => anchorRef.current,
|
|
214
196
|
isStale,
|
|
215
197
|
frame => {
|
|
216
198
|
setAnchorPosition(frame);
|
|
217
|
-
// Reopened during its own fade-out: isReady stays true, so fade back in.
|
|
218
199
|
if (isVisibleRef.current) {
|
|
219
200
|
animate(true);
|
|
220
201
|
}
|
package/package.json
CHANGED
package/renderButtons.tsx
CHANGED
package/utils.ts
CHANGED
|
@@ -10,11 +10,8 @@ type Size = { width: number; height: number };
|
|
|
10
10
|
const ARROW_WIDTH = 12;
|
|
11
11
|
const ARROW_HEIGHT = 6;
|
|
12
12
|
const ARROW_GAP = Spacing.XS;
|
|
13
|
-
// Distance from the bubble's start edge to the arrow tip for start/end align.
|
|
14
13
|
const ARROW_EDGE_INSET = Spacing.M + ARROW_WIDTH / 2;
|
|
15
|
-
// Bubble edge to anchor edge: arrow depth plus the gap to the anchor.
|
|
16
14
|
const TOOLTIP_OFFSET = ARROW_HEIGHT + ARROW_GAP;
|
|
17
|
-
// Sides to try in order: the requested one, its opposite, then the other axis.
|
|
18
15
|
const PLACEMENT_FALLBACKS: Record<TooltipPlacement, TooltipPlacement[]> = {
|
|
19
16
|
top: ['top', 'bottom', 'right', 'left'],
|
|
20
17
|
bottom: ['bottom', 'top', 'right', 'left'],
|
|
@@ -22,10 +19,6 @@ const PLACEMENT_FALLBACKS: Record<TooltipPlacement, TooltipPlacement[]> = {
|
|
|
22
19
|
right: ['right', 'left', 'top', 'bottom'],
|
|
23
20
|
};
|
|
24
21
|
|
|
25
|
-
/**
|
|
26
|
-
* Start of the bubble on the cross axis so the arrow tip lands on the anchor
|
|
27
|
-
* center: tip 18 from the start edge, centered, or 18 from the end edge.
|
|
28
|
-
*/
|
|
29
22
|
const getCrossAxisStart = (
|
|
30
23
|
anchorCenter: number,
|
|
31
24
|
tooltipLength: number,
|
|
@@ -40,7 +33,6 @@ const getCrossAxisStart = (
|
|
|
40
33
|
return anchorCenter - tooltipLength / 2;
|
|
41
34
|
};
|
|
42
35
|
|
|
43
|
-
/** Whether the bubble fits between the anchor and the window edge on that side. */
|
|
44
36
|
const hasMainAxisRoom = (
|
|
45
37
|
anchor: Frame,
|
|
46
38
|
size: Size,
|
|
@@ -61,7 +53,6 @@ const hasMainAxisRoom = (
|
|
|
61
53
|
return bubbleEnd <= window.width;
|
|
62
54
|
};
|
|
63
55
|
|
|
64
|
-
/** Whether the bubble stays inside the window along the anchor's edge. */
|
|
65
56
|
const hasCrossAxisRoom = (
|
|
66
57
|
anchor: Frame,
|
|
67
58
|
size: Size,
|
|
@@ -79,7 +70,6 @@ const hasCrossAxisRoom = (
|
|
|
79
70
|
return start >= 0 && start + length <= limit;
|
|
80
71
|
};
|
|
81
72
|
|
|
82
|
-
/** Aligns to try in order: the requested one first, then its mirror, then the rest. */
|
|
83
73
|
const getAlignCandidates = (align: Align): Align[] => {
|
|
84
74
|
if (align === 'start') {
|
|
85
75
|
return ['start', 'end', 'center'];
|
|
@@ -90,10 +80,6 @@ const getAlignCandidates = (align: Align): Align[] => {
|
|
|
90
80
|
return ['center', 'start', 'end'];
|
|
91
81
|
};
|
|
92
82
|
|
|
93
|
-
/**
|
|
94
|
-
* Placement and align that keep the bubble inside the window: the first side
|
|
95
|
-
* with room for both, or the requested values when nothing fits.
|
|
96
|
-
*/
|
|
97
83
|
export const getFlippedPosition = ({
|
|
98
84
|
anchorPosition,
|
|
99
85
|
tooltipSize,
|
|
@@ -124,10 +110,6 @@ export const getFlippedPosition = ({
|
|
|
124
110
|
return { placement, align };
|
|
125
111
|
};
|
|
126
112
|
|
|
127
|
-
/**
|
|
128
|
-
* Top/left of the bubble inside the portal host: the anchor's window frame
|
|
129
|
-
* minus the host origin, pushed out by offset and aligned start/center/end.
|
|
130
|
-
*/
|
|
131
113
|
export const getPlacementStyle = ({
|
|
132
114
|
anchorPosition,
|
|
133
115
|
tooltipSize,
|
|
@@ -178,10 +160,6 @@ export const getPlacementStyle = ({
|
|
|
178
160
|
return position;
|
|
179
161
|
};
|
|
180
162
|
|
|
181
|
-
/**
|
|
182
|
-
* Sharp 12x6 triangle on the bubble edge facing the anchor, built with the
|
|
183
|
-
* border trick; its tip sits ARROW_EDGE_INSET from the start edge for start/end.
|
|
184
|
-
*/
|
|
185
163
|
export const getTooltipArrowStyle = ({
|
|
186
164
|
align,
|
|
187
165
|
placement,
|