rn-smart-tour 2.2.0 → 2.2.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.
- package/README.md +17 -1
- package/lib/commonjs/react/TourOverlay.js +58 -6
- package/lib/commonjs/react/TourOverlay.js.map +1 -1
- package/lib/commonjs/react/TourProvider.js +4 -2
- package/lib/commonjs/react/TourProvider.js.map +1 -1
- package/lib/commonjs/react/placement.js +28 -10
- package/lib/commonjs/react/placement.js.map +1 -1
- package/lib/module/react/TourOverlay.js +59 -7
- package/lib/module/react/TourOverlay.js.map +1 -1
- package/lib/module/react/TourProvider.js +4 -2
- package/lib/module/react/TourProvider.js.map +1 -1
- package/lib/module/react/placement.js +28 -10
- package/lib/module/react/placement.js.map +1 -1
- package/lib/typescript/commonjs/src/react/TourOverlay.d.ts +10 -0
- package/lib/typescript/commonjs/src/react/TourOverlay.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/react/TourProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/react/placement.d.ts +11 -1
- package/lib/typescript/commonjs/src/react/placement.d.ts.map +1 -1
- package/lib/typescript/module/src/react/TourOverlay.d.ts +10 -0
- package/lib/typescript/module/src/react/TourOverlay.d.ts.map +1 -1
- package/lib/typescript/module/src/react/TourProvider.d.ts.map +1 -1
- package/lib/typescript/module/src/react/placement.d.ts +11 -1
- package/lib/typescript/module/src/react/placement.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/react/TourOverlay.tsx +72 -4
- package/src/react/TourProvider.tsx +3 -0
- package/src/react/placement.ts +34 -15
package/src/react/placement.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { TargetMeasurement as Rect, TourStep } from '../types';
|
|
|
4
4
|
const TOOLTIP_GAP = 10;
|
|
5
5
|
/** Minimum distance between the card and the screen edges. */
|
|
6
6
|
const EDGE_PADDING = 16;
|
|
7
|
+
/** Space kept between the card and a safe-area inset (status bar, home indicator). */
|
|
8
|
+
const SAFE_AREA_GAP = 8;
|
|
7
9
|
/** Narrowest card worth showing beside a target for 'left' / 'right'; otherwise it goes above/below. */
|
|
8
10
|
const MIN_SIDE_WIDTH = 160;
|
|
9
11
|
|
|
@@ -19,6 +21,11 @@ export interface TooltipPlacement {
|
|
|
19
21
|
* Where to put the tooltip card. Uses the card's measured height, prefers the
|
|
20
22
|
* step's `position`, and flips to the other side when it doesn't fit. Without a
|
|
21
23
|
* target rect (a centred step) the card goes in the middle of the screen.
|
|
24
|
+
*
|
|
25
|
+
* `screenWidth` × `screenHeight` is the area the user sees (the window); `areaLeft` /
|
|
26
|
+
* `areaTop` is where it starts in the layer's coordinates. They are 0 unless the layer
|
|
27
|
+
* starts above or left of the window — e.g. under an Android status bar when the app
|
|
28
|
+
* isn't edge-to-edge — so the card stays clear of the part hidden behind the bar.
|
|
22
29
|
*/
|
|
23
30
|
export function placeTooltip({
|
|
24
31
|
rect,
|
|
@@ -27,6 +34,10 @@ export function placeTooltip({
|
|
|
27
34
|
screenHeight,
|
|
28
35
|
position = 'bottom',
|
|
29
36
|
width,
|
|
37
|
+
areaLeft = 0,
|
|
38
|
+
areaTop = 0,
|
|
39
|
+
safeTop = 0,
|
|
40
|
+
safeBottom = 0,
|
|
30
41
|
}: {
|
|
31
42
|
rect: Rect | null;
|
|
32
43
|
cardHeight: number;
|
|
@@ -34,27 +45,34 @@ export function placeTooltip({
|
|
|
34
45
|
screenHeight: number;
|
|
35
46
|
position?: TourStep['position'];
|
|
36
47
|
width: number;
|
|
48
|
+
areaLeft?: number;
|
|
49
|
+
areaTop?: number;
|
|
50
|
+
/** Safe-area insets of the window (status bar / notch, home indicator): the card stays clear of them. */
|
|
51
|
+
safeTop?: number;
|
|
52
|
+
safeBottom?: number;
|
|
37
53
|
}): TooltipPlacement {
|
|
38
54
|
const cardWidth = Math.min(width, screenWidth - EDGE_PADDING * 2);
|
|
55
|
+
const topClearance = Math.max(EDGE_PADDING, safeTop + SAFE_AREA_GAP);
|
|
56
|
+
const bottomClearance = Math.max(EDGE_PADDING, safeBottom + SAFE_AREA_GAP);
|
|
57
|
+
const minTop = areaTop + topClearance;
|
|
58
|
+
const maxTop = areaTop + screenHeight - bottomClearance - cardHeight;
|
|
59
|
+
const bottomEdge = areaTop + screenHeight;
|
|
60
|
+
const rightEdge = areaLeft + screenWidth;
|
|
39
61
|
|
|
40
62
|
if (!rect) {
|
|
41
63
|
return {
|
|
42
|
-
left: (screenWidth - cardWidth) / 2,
|
|
43
|
-
top: clamp((screenHeight - cardHeight) / 2,
|
|
64
|
+
left: areaLeft + (screenWidth - cardWidth) / 2,
|
|
65
|
+
top: clamp(areaTop + (screenHeight - cardHeight) / 2, minTop, maxTop),
|
|
44
66
|
width: cardWidth,
|
|
45
67
|
};
|
|
46
68
|
}
|
|
47
|
-
const centeredTop = clamp(
|
|
48
|
-
rect.y + rect.height / 2 - cardHeight / 2,
|
|
49
|
-
EDGE_PADDING,
|
|
50
|
-
screenHeight - EDGE_PADDING - cardHeight,
|
|
51
|
-
);
|
|
69
|
+
const centeredTop = clamp(rect.y + rect.height / 2 - cardHeight / 2, minTop, maxTop);
|
|
52
70
|
|
|
53
71
|
if (position === 'left' || position === 'right') {
|
|
54
72
|
const room =
|
|
55
73
|
position === 'left'
|
|
56
|
-
? rect.x - TOOLTIP_GAP - EDGE_PADDING
|
|
57
|
-
:
|
|
74
|
+
? rect.x - areaLeft - TOOLTIP_GAP - EDGE_PADDING
|
|
75
|
+
: rightEdge - (rect.x + rect.width) - TOOLTIP_GAP - EDGE_PADDING;
|
|
58
76
|
if (room >= Math.min(cardWidth, MIN_SIDE_WIDTH)) {
|
|
59
77
|
const sideWidth = Math.min(cardWidth, room);
|
|
60
78
|
return {
|
|
@@ -68,8 +86,8 @@ export function placeTooltip({
|
|
|
68
86
|
|
|
69
87
|
const below = rect.y + rect.height + TOOLTIP_GAP;
|
|
70
88
|
const above = rect.y - TOOLTIP_GAP - cardHeight;
|
|
71
|
-
const fitsBelow = below + cardHeight <=
|
|
72
|
-
const fitsAbove = above >=
|
|
89
|
+
const fitsBelow = below + cardHeight <= bottomEdge - bottomClearance;
|
|
90
|
+
const fitsAbove = above >= minTop;
|
|
73
91
|
|
|
74
92
|
let top: number;
|
|
75
93
|
if (position === 'top') {
|
|
@@ -79,15 +97,16 @@ export function placeTooltip({
|
|
|
79
97
|
}
|
|
80
98
|
if (Number.isNaN(top)) {
|
|
81
99
|
// Fits neither way (e.g. a very tall target): use the roomier side, kept on screen.
|
|
82
|
-
const roomBelow =
|
|
83
|
-
|
|
100
|
+
const roomBelow = bottomEdge - (rect.y + rect.height);
|
|
101
|
+
const roomAbove = rect.y - areaTop;
|
|
102
|
+
top = clamp(roomBelow >= roomAbove ? below : above, minTop, maxTop);
|
|
84
103
|
}
|
|
85
104
|
|
|
86
105
|
return {
|
|
87
106
|
left: clamp(
|
|
88
107
|
rect.x + rect.width / 2 - cardWidth / 2,
|
|
89
|
-
EDGE_PADDING,
|
|
90
|
-
|
|
108
|
+
areaLeft + EDGE_PADDING,
|
|
109
|
+
rightEdge - cardWidth - EDGE_PADDING,
|
|
91
110
|
),
|
|
92
111
|
top,
|
|
93
112
|
width: cardWidth,
|