@pgy-eu/react-native-tour-guide 0.0.0-stage → 0.0.1

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.
Files changed (161) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +993 -2
  3. package/lib/commonjs/SpotlightOverlay.js +712 -0
  4. package/lib/commonjs/SpotlightOverlay.js.map +1 -0
  5. package/lib/commonjs/Tooltip.js +593 -0
  6. package/lib/commonjs/Tooltip.js.map +1 -0
  7. package/lib/commonjs/TourGuideContext.js +535 -0
  8. package/lib/commonjs/TourGuideContext.js.map +1 -0
  9. package/lib/commonjs/TourGuideOverlay.js +1173 -0
  10. package/lib/commonjs/TourGuideOverlay.js.map +1 -0
  11. package/lib/commonjs/TourTarget.js +80 -0
  12. package/lib/commonjs/TourTarget.js.map +1 -0
  13. package/lib/commonjs/accessibility.js +49 -0
  14. package/lib/commonjs/accessibility.js.map +1 -0
  15. package/lib/commonjs/dev.js +48 -0
  16. package/lib/commonjs/dev.js.map +1 -0
  17. package/lib/commonjs/events.js +56 -0
  18. package/lib/commonjs/events.js.map +1 -0
  19. package/lib/commonjs/index.js +169 -0
  20. package/lib/commonjs/index.js.map +1 -0
  21. package/lib/commonjs/package.json +1 -0
  22. package/lib/commonjs/shapes.js +158 -0
  23. package/lib/commonjs/shapes.js.map +1 -0
  24. package/lib/commonjs/storage.js +116 -0
  25. package/lib/commonjs/storage.js.map +1 -0
  26. package/lib/commonjs/themes.js +86 -0
  27. package/lib/commonjs/themes.js.map +1 -0
  28. package/lib/commonjs/types.js +6 -0
  29. package/lib/commonjs/types.js.map +1 -0
  30. package/lib/commonjs/useTourPersistence.js +135 -0
  31. package/lib/commonjs/useTourPersistence.js.map +1 -0
  32. package/lib/commonjs/useTourScroll.js +46 -0
  33. package/lib/commonjs/useTourScroll.js.map +1 -0
  34. package/lib/commonjs/utils.js +372 -0
  35. package/lib/commonjs/utils.js.map +1 -0
  36. package/lib/commonjs/validation.js +143 -0
  37. package/lib/commonjs/validation.js.map +1 -0
  38. package/lib/module/SpotlightOverlay.js +707 -0
  39. package/lib/module/SpotlightOverlay.js.map +1 -0
  40. package/lib/module/Tooltip.js +588 -0
  41. package/lib/module/Tooltip.js.map +1 -0
  42. package/lib/module/TourGuideContext.js +529 -0
  43. package/lib/module/TourGuideContext.js.map +1 -0
  44. package/lib/module/TourGuideOverlay.js +1167 -0
  45. package/lib/module/TourGuideOverlay.js.map +1 -0
  46. package/lib/module/TourTarget.js +74 -0
  47. package/lib/module/TourTarget.js.map +1 -0
  48. package/lib/module/accessibility.js +43 -0
  49. package/lib/module/accessibility.js.map +1 -0
  50. package/lib/module/dev.js +40 -0
  51. package/lib/module/dev.js.map +1 -0
  52. package/lib/module/events.js +51 -0
  53. package/lib/module/events.js.map +1 -0
  54. package/lib/module/index.js +25 -0
  55. package/lib/module/index.js.map +1 -0
  56. package/lib/module/package.json +1 -0
  57. package/lib/module/shapes.js +152 -0
  58. package/lib/module/shapes.js.map +1 -0
  59. package/lib/module/storage.js +111 -0
  60. package/lib/module/storage.js.map +1 -0
  61. package/lib/module/themes.js +81 -0
  62. package/lib/module/themes.js.map +1 -0
  63. package/lib/module/types.js +4 -0
  64. package/lib/module/types.js.map +1 -0
  65. package/lib/module/useTourPersistence.js +130 -0
  66. package/lib/module/useTourPersistence.js.map +1 -0
  67. package/lib/module/useTourScroll.js +41 -0
  68. package/lib/module/useTourScroll.js.map +1 -0
  69. package/lib/module/utils.js +361 -0
  70. package/lib/module/utils.js.map +1 -0
  71. package/lib/module/validation.js +138 -0
  72. package/lib/module/validation.js.map +1 -0
  73. package/lib/typescript/commonjs/package.json +1 -0
  74. package/lib/typescript/commonjs/src/SpotlightOverlay.d.ts +46 -0
  75. package/lib/typescript/commonjs/src/SpotlightOverlay.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/Tooltip.d.ts +9 -0
  77. package/lib/typescript/commonjs/src/Tooltip.d.ts.map +1 -0
  78. package/lib/typescript/commonjs/src/TourGuideContext.d.ts +46 -0
  79. package/lib/typescript/commonjs/src/TourGuideContext.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/src/TourGuideOverlay.d.ts +22 -0
  81. package/lib/typescript/commonjs/src/TourGuideOverlay.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/src/TourTarget.d.ts +36 -0
  83. package/lib/typescript/commonjs/src/TourTarget.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/src/accessibility.d.ts +22 -0
  85. package/lib/typescript/commonjs/src/accessibility.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/dev.d.ts +22 -0
  87. package/lib/typescript/commonjs/src/dev.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/events.d.ts +57 -0
  89. package/lib/typescript/commonjs/src/events.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/index.d.ts +21 -0
  91. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/shapes.d.ts +50 -0
  93. package/lib/typescript/commonjs/src/shapes.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/storage.d.ts +15 -0
  95. package/lib/typescript/commonjs/src/storage.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/themes.d.ts +10 -0
  97. package/lib/typescript/commonjs/src/themes.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/types.d.ts +599 -0
  99. package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/useTourPersistence.d.ts +63 -0
  101. package/lib/typescript/commonjs/src/useTourPersistence.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/useTourScroll.d.ts +36 -0
  103. package/lib/typescript/commonjs/src/useTourScroll.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/utils.d.ts +97 -0
  105. package/lib/typescript/commonjs/src/utils.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/validation.d.ts +11 -0
  107. package/lib/typescript/commonjs/src/validation.d.ts.map +1 -0
  108. package/lib/typescript/module/package.json +1 -0
  109. package/lib/typescript/module/src/SpotlightOverlay.d.ts +46 -0
  110. package/lib/typescript/module/src/SpotlightOverlay.d.ts.map +1 -0
  111. package/lib/typescript/module/src/Tooltip.d.ts +9 -0
  112. package/lib/typescript/module/src/Tooltip.d.ts.map +1 -0
  113. package/lib/typescript/module/src/TourGuideContext.d.ts +46 -0
  114. package/lib/typescript/module/src/TourGuideContext.d.ts.map +1 -0
  115. package/lib/typescript/module/src/TourGuideOverlay.d.ts +22 -0
  116. package/lib/typescript/module/src/TourGuideOverlay.d.ts.map +1 -0
  117. package/lib/typescript/module/src/TourTarget.d.ts +36 -0
  118. package/lib/typescript/module/src/TourTarget.d.ts.map +1 -0
  119. package/lib/typescript/module/src/accessibility.d.ts +22 -0
  120. package/lib/typescript/module/src/accessibility.d.ts.map +1 -0
  121. package/lib/typescript/module/src/dev.d.ts +22 -0
  122. package/lib/typescript/module/src/dev.d.ts.map +1 -0
  123. package/lib/typescript/module/src/events.d.ts +57 -0
  124. package/lib/typescript/module/src/events.d.ts.map +1 -0
  125. package/lib/typescript/module/src/index.d.ts +21 -0
  126. package/lib/typescript/module/src/index.d.ts.map +1 -0
  127. package/lib/typescript/module/src/shapes.d.ts +50 -0
  128. package/lib/typescript/module/src/shapes.d.ts.map +1 -0
  129. package/lib/typescript/module/src/storage.d.ts +15 -0
  130. package/lib/typescript/module/src/storage.d.ts.map +1 -0
  131. package/lib/typescript/module/src/themes.d.ts +10 -0
  132. package/lib/typescript/module/src/themes.d.ts.map +1 -0
  133. package/lib/typescript/module/src/types.d.ts +599 -0
  134. package/lib/typescript/module/src/types.d.ts.map +1 -0
  135. package/lib/typescript/module/src/useTourPersistence.d.ts +63 -0
  136. package/lib/typescript/module/src/useTourPersistence.d.ts.map +1 -0
  137. package/lib/typescript/module/src/useTourScroll.d.ts +36 -0
  138. package/lib/typescript/module/src/useTourScroll.d.ts.map +1 -0
  139. package/lib/typescript/module/src/utils.d.ts +97 -0
  140. package/lib/typescript/module/src/utils.d.ts.map +1 -0
  141. package/lib/typescript/module/src/validation.d.ts +11 -0
  142. package/lib/typescript/module/src/validation.d.ts.map +1 -0
  143. package/llms.txt +62 -0
  144. package/package.json +281 -4
  145. package/src/SpotlightOverlay.tsx +742 -0
  146. package/src/Tooltip.tsx +638 -0
  147. package/src/TourGuideContext.tsx +644 -0
  148. package/src/TourGuideOverlay.tsx +1382 -0
  149. package/src/TourTarget.tsx +74 -0
  150. package/src/accessibility.ts +60 -0
  151. package/src/dev.ts +39 -0
  152. package/src/events.ts +76 -0
  153. package/src/index.tsx +64 -0
  154. package/src/shapes.ts +184 -0
  155. package/src/storage.ts +114 -0
  156. package/src/themes.ts +83 -0
  157. package/src/types.ts +648 -0
  158. package/src/useTourPersistence.ts +147 -0
  159. package/src/useTourScroll.ts +60 -0
  160. package/src/utils.ts +401 -0
  161. package/src/validation.ts +248 -0
@@ -0,0 +1,638 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import { View, Text, Pressable, ScrollView, StyleSheet, Platform } from 'react-native';
3
+ import type { LayoutChangeEvent } from 'react-native';
4
+
5
+ import type { ResolvedTourGuideConfig, TooltipProps } from './types';
6
+ import { computeTooltipPosition, isLightColor } from './utils';
7
+ import { getTooltipAccessibilityProps } from './accessibility';
8
+
9
+ const DEFAULT_CONFIG: ResolvedTourGuideConfig = {};
10
+
11
+ const DEFAULT_TOOLTIP_WIDTH = 320;
12
+ // Never shrink the body below this, even in a very tight corner — a narrower
13
+ // tooltip is unreadable, and overflowing slightly is the better failure.
14
+ const MIN_TOOLTIP_WIDTH = 100;
15
+ const DEFAULT_TRIANGLE_SIZE = 12;
16
+ const DEFAULT_OFFSET = 8;
17
+
18
+ // Module-scoped so it's a stable reference used as a default prop (an inline
19
+ // object literal default re-creates each render and can cause render loops).
20
+ const ZERO_INSETS = { top: 0, bottom: 0, left: 0, right: 0 };
21
+
22
+ /**
23
+ * Tooltip component that displays tour information.
24
+ * Supports automatic positioning and customizable styling.
25
+ */
26
+ const Tooltip: React.FC<TooltipProps> = ({
27
+ title,
28
+ description,
29
+ position,
30
+ tooltipPosition: tooltipPositionProp = 'bottom',
31
+ currentStep,
32
+ totalSteps,
33
+ onNext,
34
+ onPrev,
35
+ onSkip,
36
+ targetHeight = 0,
37
+ targetWidth = 0,
38
+ config = DEFAULT_CONFIG,
39
+ hideNextButton = false,
40
+ hidePrevButton = false,
41
+ hideSkipButton = false,
42
+ screenWidth = 0,
43
+ screenHeight = 0,
44
+ insets = ZERO_INSETS,
45
+ nextDisabled = false,
46
+ isLastStep,
47
+ }) => {
48
+ const {
49
+ tooltipStyles: tooltipStylesConfig,
50
+ showProgressDots = false,
51
+ showStepCounter = true,
52
+ enableBackButton = true,
53
+ nextButtonText = 'Next',
54
+ prevButtonText = 'Back',
55
+ skipButtonText = 'Skip',
56
+ doneButtonText = 'Done',
57
+ tooltipWidth: configTooltipWidth,
58
+ triangleSize: configTriangleSize,
59
+ tooltipOffset: configTooltipOffset,
60
+ components = {},
61
+ allowFontScaling = true,
62
+ maxFontSizeMultiplier,
63
+ } = config;
64
+
65
+ // Shared props for every Text node: respect the OS font-size setting, with an
66
+ // optional cap so extreme sizes don't explode the layout.
67
+ const textScaleProps = { allowFontScaling, maxFontSizeMultiplier };
68
+
69
+ const TOOLTIP_WIDTH = configTooltipWidth ?? DEFAULT_TOOLTIP_WIDTH;
70
+ const TRIANGLE_SIZE = configTriangleSize ?? DEFAULT_TRIANGLE_SIZE;
71
+ const OFFSET = configTooltipOffset ?? DEFAULT_OFFSET;
72
+
73
+ // Readable-by-default: when a consumer sets a custom tooltip background but
74
+ // no text colors, derive dark-on-light or light-on-dark defaults from that
75
+ // background instead of assuming white text. A pale background with the old
76
+ // hard-coded white title rendered invisible text.
77
+ const backgroundColor = tooltipStylesConfig?.backgroundColor ?? '#2C2C2E';
78
+ const bgIsLight = isLightColor(backgroundColor) === true;
79
+ const autoInk = bgIsLight ? '#1C1C1E' : '#FFFFFF';
80
+ const autoSecondary = bgIsLight ? '#E5E5EA' : '#3A3A3C';
81
+
82
+ const {
83
+ borderRadius = 16,
84
+ titleColor = autoInk,
85
+ descriptionColor = autoInk,
86
+ buttonTextColor = '#FFFFFF',
87
+ primaryButtonColor = '#007AFF',
88
+ secondaryButtonColor = autoSecondary,
89
+ skipButtonColor = autoInk,
90
+ titleStyle: customTitleStyle,
91
+ descriptionStyle: customDescriptionStyle,
92
+ containerStyle: customContainerStyle,
93
+ arrowStyle: customArrowStyle,
94
+ } = tooltipStylesConfig ?? {};
95
+
96
+ // Secondary (Back) button text must read against the BUTTON's own
97
+ // background — not the tooltip's. A consumer may set a dark
98
+ // secondaryButtonColor on a light tooltip (or vice versa); deriving from the
99
+ // tooltip background would render unreadable text on that button.
100
+ // Unparseable button color → fall back to the tooltip-background derivation.
101
+ const secondaryIsLight = isLightColor(secondaryButtonColor) ?? bgIsLight;
102
+ const secondaryTextColor =
103
+ tooltipStylesConfig?.buttonTextColor ?? (secondaryIsLight ? '#1C1C1E' : '#FFFFFF');
104
+
105
+ const targetCenterX = position.x + targetWidth / 2;
106
+
107
+ // Measure the tooltip's real height so we can keep it fully on-screen. Until
108
+ // the first layout pass we use a conservative estimate.
109
+ const [measuredHeight, setMeasuredHeight] = useState(0);
110
+ const H = measuredHeight || 160;
111
+ const onBodyLayout = (e: LayoutChangeEvent) => {
112
+ const h = e.nativeEvent.layout.height;
113
+ if (h > 0 && Math.abs(h - measuredHeight) > 1) setMeasuredHeight(h);
114
+ };
115
+
116
+ // Smart auto-positioning
117
+ const tooltipPosition = useMemo(() => {
118
+ if (tooltipPositionProp === 'auto' && screenWidth > 0 && screenHeight > 0) {
119
+ return computeTooltipPosition({
120
+ target: { x: position.x, y: position.y, width: targetWidth, height: targetHeight },
121
+ screenWidth,
122
+ screenHeight,
123
+ tooltipWidth: TOOLTIP_WIDTH,
124
+ tooltipHeight: 150,
125
+ offset: OFFSET + TRIANGLE_SIZE,
126
+ // Without the insets a tooltip could be placed under the status bar or
127
+ // behind the home indicator / navigation bar.
128
+ insets,
129
+ });
130
+ }
131
+
132
+ if (tooltipPositionProp === 'auto') return 'bottom';
133
+ return tooltipPositionProp;
134
+ }, [
135
+ tooltipPositionProp,
136
+ position.x,
137
+ position.y,
138
+ targetWidth,
139
+ targetHeight,
140
+ screenWidth,
141
+ screenHeight,
142
+ TOOLTIP_WIDTH,
143
+ OFFSET,
144
+ TRIANGLE_SIZE,
145
+ insets,
146
+ ]);
147
+
148
+ // Compute tooltip body position and style
149
+ const tooltipBodyStyle = useMemo(() => {
150
+ if (tooltipPosition === 'top' || tooltipPosition === 'bottom') {
151
+ const pad = 16;
152
+ const idealLeft = targetCenterX - TOOLTIP_WIDTH / 2;
153
+ const minLeft = insets.left + pad;
154
+ const maxLeft = screenWidth - insets.right - TOOLTIP_WIDTH - pad;
155
+ // Guard against negative range on very narrow screens.
156
+ const clampedLeft = Math.max(minLeft, Math.min(idealLeft, Math.max(minLeft, maxLeft)));
157
+
158
+ return { left: clampedLeft, maxWidth: TOOLTIP_WIDTH, minWidth: MIN_TOOLTIP_WIDTH };
159
+ }
160
+ // Side placements size themselves via the container (see `placement`).
161
+ return { left: undefined as number | undefined, minWidth: MIN_TOOLTIP_WIDTH };
162
+ }, [tooltipPosition, targetCenterX, TOOLTIP_WIDTH, screenWidth, insets.left, insets.right]);
163
+
164
+ // Compute the container position. Vertical placement is always expressed as an
165
+ // absolute `top` and clamped against the measured height so the tooltip can
166
+ // never run off the top or bottom of the screen (the off-screen bug).
167
+ const placement = useMemo(() => {
168
+ const SAFE_MARGIN = 8;
169
+ const minTop = insets.top + SAFE_MARGIN;
170
+ const maxTop = screenHeight - insets.bottom - H - SAFE_MARGIN;
171
+ const clampTop = (t: number) => Math.max(minTop, Math.min(t, Math.max(minTop, maxTop)));
172
+
173
+ switch (tooltipPosition) {
174
+ case 'top': {
175
+ const top = clampTop(position.y - OFFSET - TRIANGLE_SIZE - H);
176
+ return { style: { top } as const, arrowVertical: undefined };
177
+ }
178
+ case 'left':
179
+ case 'right': {
180
+ const top = clampTop(position.y + targetHeight / 2 - H / 2);
181
+ const PAD = 8;
182
+
183
+ // Side placements had no horizontal clamp: a target near the screen edge
184
+ // pushed the tooltip partly (or entirely) off-screen. Shrink the tooltip
185
+ // to the space that actually exists, then pin it inside the insets.
186
+ const available =
187
+ tooltipPosition === 'left'
188
+ ? position.x - OFFSET - TRIANGLE_SIZE - insets.left - PAD
189
+ : screenWidth -
190
+ insets.right -
191
+ (position.x + targetWidth + OFFSET + TRIANGLE_SIZE) -
192
+ PAD;
193
+ const width = Math.max(MIN_TOOLTIP_WIDTH, Math.min(TOOLTIP_WIDTH, available));
194
+
195
+ const horizontal =
196
+ tooltipPosition === 'left'
197
+ ? {
198
+ right: Math.min(
199
+ screenWidth - position.x + OFFSET + TRIANGLE_SIZE,
200
+ screenWidth - insets.left - width - PAD
201
+ ),
202
+ maxWidth: width,
203
+ }
204
+ : {
205
+ left: Math.max(
206
+ insets.left + PAD,
207
+ Math.min(
208
+ position.x + targetWidth + OFFSET + TRIANGLE_SIZE,
209
+ screenWidth - insets.right - width - PAD
210
+ )
211
+ ),
212
+ maxWidth: width,
213
+ };
214
+ // Keep the arrow pointing at the target's vertical center, but clamp it
215
+ // within the (possibly repositioned) tooltip body.
216
+ const rawArrow = position.y + targetHeight / 2 - top - TRIANGLE_SIZE;
217
+ const arrowVertical = Math.max(
218
+ borderRadius,
219
+ Math.min(rawArrow, H - borderRadius - TRIANGLE_SIZE * 2)
220
+ );
221
+ return { style: { ...horizontal, top }, arrowVertical };
222
+ }
223
+ case 'bottom':
224
+ default: {
225
+ const top = clampTop(position.y + targetHeight + OFFSET + TRIANGLE_SIZE);
226
+ return { style: { top } as const, arrowVertical: undefined };
227
+ }
228
+ }
229
+ }, [
230
+ tooltipPosition,
231
+ position.x,
232
+ position.y,
233
+ targetWidth,
234
+ targetHeight,
235
+ screenWidth,
236
+ screenHeight,
237
+ H,
238
+ OFFSET,
239
+ TRIANGLE_SIZE,
240
+ borderRadius,
241
+ TOOLTIP_WIDTH,
242
+ insets.top,
243
+ insets.bottom,
244
+ insets.left,
245
+ insets.right,
246
+ ]);
247
+
248
+ const getTriangleStyle = () => {
249
+ const baseTriangle = {
250
+ width: 0,
251
+ height: 0,
252
+ backgroundColor: 'transparent',
253
+ position: 'absolute' as const,
254
+ };
255
+
256
+ // Arrow tip should point at targetCenterX (screen coordinate).
257
+ // The triangle is inside tooltipWrapper which starts at screen x=0,
258
+ // so its `left` is in screen coordinates.
259
+ // Clamp so arrow stays visually within the tooltip body.
260
+ const tooltipLeft = tooltipBodyStyle.left ?? 0;
261
+ const rawTriangleLeft = targetCenterX - TRIANGLE_SIZE;
262
+ const minTriangle = tooltipLeft + borderRadius;
263
+ const maxTriangle = tooltipLeft + TOOLTIP_WIDTH - borderRadius - TRIANGLE_SIZE * 2;
264
+ const relativeTriangleLeft = Math.max(minTriangle, Math.min(rawTriangleLeft, maxTriangle));
265
+
266
+ // Overlap arrow by 1px to eliminate subpixel gap
267
+ const OVERLAP = 1;
268
+
269
+ switch (tooltipPosition) {
270
+ case 'top':
271
+ return {
272
+ ...baseTriangle,
273
+ borderLeftWidth: TRIANGLE_SIZE,
274
+ borderRightWidth: TRIANGLE_SIZE,
275
+ borderLeftColor: 'transparent',
276
+ borderRightColor: 'transparent',
277
+ borderTopColor: backgroundColor,
278
+ borderTopWidth: TRIANGLE_SIZE,
279
+ bottom: -TRIANGLE_SIZE + OVERLAP,
280
+ left: relativeTriangleLeft,
281
+ };
282
+ case 'bottom':
283
+ return {
284
+ ...baseTriangle,
285
+ borderLeftWidth: TRIANGLE_SIZE,
286
+ borderRightWidth: TRIANGLE_SIZE,
287
+ borderLeftColor: 'transparent',
288
+ borderRightColor: 'transparent',
289
+ borderBottomColor: backgroundColor,
290
+ borderBottomWidth: TRIANGLE_SIZE,
291
+ top: -TRIANGLE_SIZE + OVERLAP,
292
+ left: relativeTriangleLeft,
293
+ };
294
+ case 'left':
295
+ return {
296
+ ...baseTriangle,
297
+ borderTopWidth: TRIANGLE_SIZE,
298
+ borderBottomWidth: TRIANGLE_SIZE,
299
+ borderTopColor: 'transparent',
300
+ borderBottomColor: 'transparent',
301
+ borderLeftColor: backgroundColor,
302
+ borderLeftWidth: TRIANGLE_SIZE,
303
+ right: -TRIANGLE_SIZE + OVERLAP,
304
+ top: placement.arrowVertical ?? 20,
305
+ };
306
+ case 'right':
307
+ return {
308
+ ...baseTriangle,
309
+ borderTopWidth: TRIANGLE_SIZE,
310
+ borderBottomWidth: TRIANGLE_SIZE,
311
+ borderTopColor: 'transparent',
312
+ borderBottomColor: 'transparent',
313
+ borderRightColor: backgroundColor,
314
+ borderRightWidth: TRIANGLE_SIZE,
315
+ left: -TRIANGLE_SIZE + OVERLAP,
316
+ top: placement.arrowVertical ?? 20,
317
+ };
318
+ default:
319
+ return {
320
+ ...baseTriangle,
321
+ borderLeftWidth: TRIANGLE_SIZE,
322
+ borderRightWidth: TRIANGLE_SIZE,
323
+ borderLeftColor: 'transparent',
324
+ borderRightColor: 'transparent',
325
+ borderBottomColor: backgroundColor,
326
+ borderBottomWidth: TRIANGLE_SIZE,
327
+ top: -TRIANGLE_SIZE + OVERLAP,
328
+ left: relativeTriangleLeft,
329
+ };
330
+ }
331
+ };
332
+
333
+ const showPrev = enableBackButton && !hidePrevButton && Boolean(onPrev) && currentStep > 0;
334
+ const showSkip = !hideSkipButton;
335
+ const showNext = !hideNextButton;
336
+ const isLast = isLastStep ?? currentStep === totalSteps - 1;
337
+ const nextLabel = isLast ? doneButtonText : nextButtonText;
338
+
339
+ // Shrink-to-fit: the tooltip body may never be taller than the space inside
340
+ // the insets — a long description on a small screen scrolls inside the body
341
+ // instead of running off-screen.
342
+ const maxBodyHeight = Math.max(
343
+ 140,
344
+ screenHeight > 0 ? screenHeight - insets.top - insets.bottom - 32 : 9999
345
+ );
346
+
347
+ const { NextButton, PrevButton, SkipButton, StepCounter, ProgressDots } = components;
348
+
349
+ // Slot resolution as plain nodes keeps the JSX below free of nested ternaries.
350
+ const skipNode =
351
+ showSkip && SkipButton ? <SkipButton label={skipButtonText} onPress={onSkip} /> : null;
352
+ const counterNode =
353
+ showStepCounter && totalSteps > 1 && StepCounter ? (
354
+ <StepCounter currentStep={currentStep} totalSteps={totalSteps} />
355
+ ) : null;
356
+ const prevNode =
357
+ showPrev && PrevButton ? (
358
+ <PrevButton label={prevButtonText} onPress={onPrev ?? (() => {})} />
359
+ ) : null;
360
+ const nextNode =
361
+ showNext && NextButton ? (
362
+ <NextButton label={nextLabel} onPress={onNext} disabled={nextDisabled} isLast={isLast} />
363
+ ) : null;
364
+
365
+ // Accessibility
366
+ const a11yProps = getTooltipAccessibilityProps(
367
+ { id: '', title, description, accessibilityLabel: undefined },
368
+ currentStep,
369
+ totalSteps,
370
+ config
371
+ );
372
+
373
+ return (
374
+ <View style={[internalStyles.container, placement.style]}>
375
+ <View style={internalStyles.tooltipWrapper}>
376
+ {/* Triangle/Arrow */}
377
+ <View style={[getTriangleStyle(), customArrowStyle]} />
378
+
379
+ {/* Tooltip Body */}
380
+ <View
381
+ {...a11yProps}
382
+ onLayout={onBodyLayout}
383
+ style={[
384
+ internalStyles.tooltipBody,
385
+ { backgroundColor, borderRadius, maxHeight: maxBodyHeight },
386
+ tooltipBodyStyle,
387
+ customContainerStyle,
388
+ ]}
389
+ >
390
+ {/* Header with title and skip */}
391
+ <View style={internalStyles.header}>
392
+ <Text
393
+ {...textScaleProps}
394
+ style={[internalStyles.titleText, { color: titleColor }, customTitleStyle]}
395
+ numberOfLines={2}
396
+ >
397
+ {title}
398
+ </Text>
399
+ {skipNode}
400
+ {showSkip && !SkipButton ? (
401
+ <Pressable
402
+ style={[internalStyles.skipButton, { borderColor: skipButtonColor }]}
403
+ onPress={onSkip}
404
+ hitSlop={8}
405
+ accessibilityRole="button"
406
+ accessibilityLabel={`${skipButtonText} tour`}
407
+ >
408
+ <Text
409
+ {...textScaleProps}
410
+ style={[internalStyles.skipText, { color: skipButtonColor }]}
411
+ >
412
+ {skipButtonText}
413
+ </Text>
414
+ </Pressable>
415
+ ) : null}
416
+ </View>
417
+
418
+ {/* Description — scrolls when the shrink-to-fit cap constrains the body */}
419
+ <ScrollView
420
+ style={internalStyles.descriptionScroll}
421
+ contentContainerStyle={internalStyles.descriptionContent}
422
+ showsVerticalScrollIndicator={false}
423
+ >
424
+ <Text
425
+ {...textScaleProps}
426
+ style={[
427
+ internalStyles.descriptionText,
428
+ { color: descriptionColor },
429
+ customDescriptionStyle,
430
+ ]}
431
+ >
432
+ {description}
433
+ </Text>
434
+ </ScrollView>
435
+
436
+ {/* Footer with progress and buttons */}
437
+ <View style={internalStyles.footer}>
438
+ {/* Progress dots */}
439
+ {showProgressDots && totalSteps > 1 && ProgressDots ? (
440
+ <ProgressDots currentStep={currentStep} totalSteps={totalSteps} />
441
+ ) : null}
442
+ {showProgressDots && totalSteps > 1 && !ProgressDots ? (
443
+ <View style={internalStyles.dotsContainer}>
444
+ {Array.from({ length: totalSteps }).map((_, index) => (
445
+ <View
446
+ key={`dot-${index}`}
447
+ style={[
448
+ internalStyles.dot,
449
+ {
450
+ backgroundColor:
451
+ index === currentStep ? primaryButtonColor : descriptionColor,
452
+ opacity: index === currentStep ? 1 : 0.3,
453
+ },
454
+ index === currentStep && internalStyles.dotActive,
455
+ ]}
456
+ />
457
+ ))}
458
+ </View>
459
+ ) : null}
460
+
461
+ {/* Navigation buttons */}
462
+ <View style={internalStyles.navigationRow}>
463
+ {/* Step counter */}
464
+ {counterNode}
465
+ {showStepCounter && totalSteps > 1 && !StepCounter ? (
466
+ <Text
467
+ {...textScaleProps}
468
+ style={[internalStyles.stepCounter, { color: descriptionColor }]}
469
+ >
470
+ {currentStep + 1}/{totalSteps}
471
+ </Text>
472
+ ) : null}
473
+
474
+ <View style={internalStyles.buttonsContainer}>
475
+ {/* Back button */}
476
+ {prevNode}
477
+ {showPrev && !PrevButton ? (
478
+ <Pressable
479
+ onPress={onPrev}
480
+ style={[internalStyles.button, { backgroundColor: secondaryButtonColor }]}
481
+ accessibilityRole="button"
482
+ accessibilityLabel={`${prevButtonText}, go to previous step`}
483
+ >
484
+ <Text
485
+ {...textScaleProps}
486
+ style={[internalStyles.buttonText, { color: secondaryTextColor }]}
487
+ >
488
+ {prevButtonText}
489
+ </Text>
490
+ </Pressable>
491
+ ) : null}
492
+ {/* Next/Done button */}
493
+ {nextNode}
494
+ {showNext && !NextButton ? (
495
+ <Pressable
496
+ onPress={onNext}
497
+ disabled={nextDisabled}
498
+ style={[
499
+ internalStyles.buttonPrimary,
500
+ { backgroundColor: primaryButtonColor },
501
+ nextDisabled && internalStyles.buttonDisabled,
502
+ ]}
503
+ accessibilityRole="button"
504
+ accessibilityState={{ disabled: nextDisabled }}
505
+ accessibilityLabel={
506
+ isLast
507
+ ? `${doneButtonText}, finish tour`
508
+ : `${nextButtonText}, go to step ${currentStep + 2}`
509
+ }
510
+ >
511
+ <Text
512
+ {...textScaleProps}
513
+ style={[internalStyles.buttonPrimaryText, { color: buttonTextColor }]}
514
+ >
515
+ {nextLabel}
516
+ </Text>
517
+ </Pressable>
518
+ ) : null}
519
+ </View>
520
+ </View>
521
+ </View>
522
+ </View>
523
+ </View>
524
+ </View>
525
+ );
526
+ };
527
+
528
+ const internalStyles = StyleSheet.create({
529
+ container: {
530
+ position: 'absolute',
531
+ zIndex: 10000,
532
+ },
533
+ tooltipWrapper: {
534
+ position: 'relative',
535
+ },
536
+ tooltipBody: {
537
+ shadowColor: '#000',
538
+ shadowOffset: { width: 0, height: 4 },
539
+ shadowOpacity: 0.2,
540
+ shadowRadius: 8,
541
+ elevation: 8,
542
+ paddingVertical: 12,
543
+ paddingHorizontal: 16,
544
+ },
545
+ header: {
546
+ flexDirection: 'row',
547
+ justifyContent: 'space-between',
548
+ alignItems: 'center',
549
+ marginBottom: 8,
550
+ },
551
+ titleText: {
552
+ fontSize: 16,
553
+ flex: 1,
554
+ ...Platform.select({
555
+ ios: { fontWeight: '600' },
556
+ android: { fontWeight: '700' },
557
+ default: { fontWeight: '600' },
558
+ }),
559
+ },
560
+ skipButton: {
561
+ borderWidth: 1,
562
+ justifyContent: 'center',
563
+ alignItems: 'center',
564
+ paddingHorizontal: 8,
565
+ paddingVertical: 4,
566
+ borderRadius: 8,
567
+ marginLeft: 8,
568
+ },
569
+ skipText: {
570
+ fontSize: 14,
571
+ fontWeight: '600',
572
+ },
573
+ descriptionScroll: {
574
+ flexShrink: 1,
575
+ marginBottom: 12,
576
+ },
577
+ descriptionContent: {
578
+ flexGrow: 0,
579
+ },
580
+ descriptionText: {
581
+ fontSize: 14,
582
+ fontWeight: '400',
583
+ lineHeight: 20,
584
+ },
585
+ buttonDisabled: {
586
+ opacity: 0.4,
587
+ },
588
+ footer: {
589
+ gap: 12,
590
+ },
591
+ dotsContainer: {
592
+ flexDirection: 'row',
593
+ gap: 6,
594
+ justifyContent: 'center',
595
+ },
596
+ dot: {
597
+ width: 6,
598
+ height: 6,
599
+ borderRadius: 3,
600
+ },
601
+ dotActive: {
602
+ width: 20,
603
+ },
604
+ navigationRow: {
605
+ flexDirection: 'row',
606
+ justifyContent: 'space-between',
607
+ alignItems: 'center',
608
+ },
609
+ stepCounter: {
610
+ fontSize: 14,
611
+ fontWeight: '500',
612
+ },
613
+ buttonsContainer: {
614
+ flexDirection: 'row',
615
+ justifyContent: 'flex-end',
616
+ gap: 8,
617
+ },
618
+ button: {
619
+ paddingHorizontal: 16,
620
+ paddingVertical: 8,
621
+ borderRadius: 8,
622
+ },
623
+ buttonText: {
624
+ fontSize: 14,
625
+ fontWeight: '600',
626
+ },
627
+ buttonPrimary: {
628
+ paddingHorizontal: 16,
629
+ paddingVertical: 8,
630
+ borderRadius: 8,
631
+ },
632
+ buttonPrimaryText: {
633
+ fontSize: 14,
634
+ fontWeight: '600',
635
+ },
636
+ });
637
+
638
+ export default Tooltip;