@digia-engage/core 1.1.1 → 2.0.0-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/README.md +134 -51
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/digia/engage/rn/DigiaModule.kt +52 -8
- package/android/src/main/java/com/digia/engage/rn/DigiaSlotViewManager.kt +6 -2
- package/android/src/main/java/com/digia/engage/rn/DigiaViewManager.kt +1 -0
- package/ios/DigiaEngageModule.m +7 -1
- package/ios/DigiaHostViewManager.swift +20 -20
- package/ios/DigiaModule.swift +8 -4
- package/lib/commonjs/Digia.js +390 -4
- package/lib/commonjs/Digia.js.map +1 -1
- package/lib/commonjs/DigiaAnchorView.js +35 -3
- package/lib/commonjs/DigiaAnchorView.js.map +1 -1
- package/lib/commonjs/DigiaGuideController.js +59 -0
- package/lib/commonjs/DigiaGuideController.js.map +1 -0
- package/lib/commonjs/DigiaHealthReporter.js +45 -0
- package/lib/commonjs/DigiaHealthReporter.js.map +1 -0
- package/lib/commonjs/DigiaProvider.js +1081 -0
- package/lib/commonjs/DigiaProvider.js.map +1 -0
- package/lib/commonjs/DigiaSlotView.js +18 -3
- package/lib/commonjs/DigiaSlotView.js.map +1 -1
- package/lib/commonjs/NativeDigiaEngage.js +14 -8
- package/lib/commonjs/NativeDigiaEngage.js.map +1 -1
- package/lib/commonjs/actionHandler.js +316 -0
- package/lib/commonjs/actionHandler.js.map +1 -0
- package/lib/commonjs/defaultInAppBrowser.js +31 -0
- package/lib/commonjs/defaultInAppBrowser.js.map +1 -0
- package/lib/commonjs/digiaAnchorRegistry.js +32 -0
- package/lib/commonjs/digiaAnchorRegistry.js.map +1 -0
- package/lib/commonjs/frequencyEvaluator.js +70 -0
- package/lib/commonjs/frequencyEvaluator.js.map +1 -0
- package/lib/commonjs/frequencyStore.js +70 -0
- package/lib/commonjs/frequencyStore.js.map +1 -0
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/templateTypes.js +2 -0
- package/lib/commonjs/templateTypes.js.map +1 -0
- package/lib/module/Digia.js +389 -4
- package/lib/module/Digia.js.map +1 -1
- package/lib/module/DigiaAnchorView.js +33 -1
- package/lib/module/DigiaAnchorView.js.map +1 -1
- package/lib/module/DigiaGuideController.js +53 -0
- package/lib/module/DigiaGuideController.js.map +1 -0
- package/lib/module/DigiaHealthReporter.js +38 -0
- package/lib/module/DigiaHealthReporter.js.map +1 -0
- package/lib/module/DigiaProvider.js +1074 -0
- package/lib/module/DigiaProvider.js.map +1 -0
- package/lib/module/DigiaSlotView.js +20 -5
- package/lib/module/DigiaSlotView.js.map +1 -1
- package/lib/module/NativeDigiaEngage.js +14 -8
- package/lib/module/NativeDigiaEngage.js.map +1 -1
- package/lib/module/actionHandler.js +311 -0
- package/lib/module/actionHandler.js.map +1 -0
- package/lib/module/defaultInAppBrowser.js +25 -0
- package/lib/module/defaultInAppBrowser.js.map +1 -0
- package/lib/module/digiaAnchorRegistry.js +26 -0
- package/lib/module/digiaAnchorRegistry.js.map +1 -0
- package/lib/module/frequencyEvaluator.js +61 -0
- package/lib/module/frequencyEvaluator.js.map +1 -0
- package/lib/module/frequencyStore.js +64 -0
- package/lib/module/frequencyStore.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/templateTypes.js +2 -0
- package/lib/module/templateTypes.js.map +1 -0
- package/lib/typescript/Digia.d.ts +35 -3
- package/lib/typescript/Digia.d.ts.map +1 -1
- package/lib/typescript/DigiaAnchorView.d.ts +5 -1
- package/lib/typescript/DigiaAnchorView.d.ts.map +1 -1
- package/lib/typescript/DigiaGuideController.d.ts +30 -0
- package/lib/typescript/DigiaGuideController.d.ts.map +1 -0
- package/lib/typescript/DigiaHealthReporter.d.ts +24 -0
- package/lib/typescript/DigiaHealthReporter.d.ts.map +1 -0
- package/lib/typescript/DigiaProvider.d.ts +3 -0
- package/lib/typescript/DigiaProvider.d.ts.map +1 -0
- package/lib/typescript/DigiaSlotView.d.ts.map +1 -1
- package/lib/typescript/NativeDigiaEngage.d.ts +10 -6
- package/lib/typescript/NativeDigiaEngage.d.ts.map +1 -1
- package/lib/typescript/actionHandler.d.ts +20 -0
- package/lib/typescript/actionHandler.d.ts.map +1 -0
- package/lib/typescript/defaultInAppBrowser.d.ts +3 -0
- package/lib/typescript/defaultInAppBrowser.d.ts.map +1 -0
- package/lib/typescript/digiaAnchorRegistry.d.ts +15 -0
- package/lib/typescript/digiaAnchorRegistry.d.ts.map +1 -0
- package/lib/typescript/frequencyEvaluator.d.ts +14 -0
- package/lib/typescript/frequencyEvaluator.d.ts.map +1 -0
- package/lib/typescript/frequencyStore.d.ts +7 -0
- package/lib/typescript/frequencyStore.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/templateTypes.d.ts +140 -0
- package/lib/typescript/templateTypes.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +163 -4
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +15 -3
- package/src/Digia.ts +439 -4
- package/src/DigiaAnchorView.tsx +30 -2
- package/src/DigiaGuideController.ts +61 -0
- package/src/DigiaHealthReporter.ts +43 -0
- package/src/DigiaProvider.tsx +778 -0
- package/src/DigiaSlotView.tsx +26 -6
- package/src/NativeDigiaEngage.ts +28 -13
- package/src/actionHandler.ts +311 -0
- package/src/defaultInAppBrowser.ts +31 -0
- package/src/digiaAnchorRegistry.ts +27 -0
- package/src/frequencyEvaluator.ts +57 -0
- package/src/frequencyStore.ts +79 -0
- package/src/index.ts +1 -0
- package/src/templateTypes.ts +121 -0
- package/src/types.ts +132 -6
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
Dimensions,
|
|
5
|
+
Modal,
|
|
6
|
+
Pressable,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Text,
|
|
9
|
+
View,
|
|
10
|
+
useWindowDimensions,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import { computePosition, flip, offset, shift } from '@floating-ui/core';
|
|
13
|
+
import Svg, { Path } from 'react-native-svg';
|
|
14
|
+
import { Digia } from './Digia';
|
|
15
|
+
import { digiaGuideController, type DigiaGuideRequest } from './DigiaGuideController';
|
|
16
|
+
import { digiaAnchorRegistry, type AnchorLayout } from './digiaAnchorRegistry';
|
|
17
|
+
import { digiaActionHandler, type ActionCallbacks } from './actionHandler';
|
|
18
|
+
import type { DismissReason } from './types';
|
|
19
|
+
import type { Action, SpotlightConfig, SpotlightStep, TooltipConfig, TooltipStep } from './templateTypes';
|
|
20
|
+
|
|
21
|
+
// ─── @floating-ui/core platform adapter ──────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
const rnCorePlatform = {
|
|
24
|
+
getElementRects: ({ reference, floating }: any) => {
|
|
25
|
+
const r = typeof reference.getBoundingClientRect === 'function'
|
|
26
|
+
? reference.getBoundingClientRect()
|
|
27
|
+
: { x: 0, y: 0, width: 0, height: 0 };
|
|
28
|
+
return {
|
|
29
|
+
reference: { x: r.x ?? r.left ?? 0, y: r.y ?? r.top ?? 0, width: r.width, height: r.height },
|
|
30
|
+
floating: { x: 0, y: 0, width: floating.w ?? 0, height: floating.h ?? 0 },
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
getDimensions: (element: any) => ({ width: element.w ?? element.width ?? 0, height: element.h ?? element.height ?? 0 }),
|
|
34
|
+
getClippingRect: () => {
|
|
35
|
+
const { width, height } = Dimensions.get('window');
|
|
36
|
+
return { x: 0, y: 0, width, height, top: 0, left: 0, bottom: height, right: width };
|
|
37
|
+
},
|
|
38
|
+
isElement: () => false,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function makeVirtualRef(layout: AnchorLayout, padding = 0) {
|
|
42
|
+
return {
|
|
43
|
+
getBoundingClientRect: () => ({
|
|
44
|
+
x: layout.pageX - padding, y: layout.pageY - padding,
|
|
45
|
+
width: layout.width + padding * 2, height: layout.height + padding * 2,
|
|
46
|
+
top: layout.pageY - padding, left: layout.pageX - padding,
|
|
47
|
+
bottom: layout.pageY + layout.height + padding,
|
|
48
|
+
right: layout.pageX + layout.width + padding,
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type FloatPos = { x: number; y: number };
|
|
54
|
+
|
|
55
|
+
// ─── Arrow component ──────────────────────────────────────────────────────────
|
|
56
|
+
//
|
|
57
|
+
// arrowOffset: pixel distance from the start of the side (left for top/bottom,
|
|
58
|
+
// top for left/right) to the arrow tip center. When provided the arrow points
|
|
59
|
+
// at the anchor; when omitted it falls back to centering.
|
|
60
|
+
|
|
61
|
+
function GuideArrow({
|
|
62
|
+
placement,
|
|
63
|
+
color,
|
|
64
|
+
borderColor,
|
|
65
|
+
size,
|
|
66
|
+
arrowOffset,
|
|
67
|
+
}: {
|
|
68
|
+
placement: string;
|
|
69
|
+
color: string;
|
|
70
|
+
borderColor: string;
|
|
71
|
+
size: number;
|
|
72
|
+
arrowOffset?: number;
|
|
73
|
+
}) {
|
|
74
|
+
const s1 = size + 1;
|
|
75
|
+
|
|
76
|
+
// Horizontal: used for top / bottom placements (left offset within bubble width)
|
|
77
|
+
const hWrap = (edge: 'top' | 'bottom') =>
|
|
78
|
+
arrowOffset !== undefined
|
|
79
|
+
? { [edge]: -s1, left: arrowOffset - s1, width: s1 * 2 }
|
|
80
|
+
: { [edge]: -s1, left: 0, right: 0 };
|
|
81
|
+
|
|
82
|
+
// Vertical: used for left / right placements (top offset within bubble height)
|
|
83
|
+
const vWrap = (edge: 'left' | 'right') =>
|
|
84
|
+
arrowOffset !== undefined
|
|
85
|
+
? { [edge]: -s1, top: arrowOffset - s1, height: s1 * 2 }
|
|
86
|
+
: { [edge]: -s1, top: 0, bottom: 0 };
|
|
87
|
+
|
|
88
|
+
if (placement === 'bottom' || placement === 'below') {
|
|
89
|
+
// bubble below anchor → arrow at TOP pointing ▲ up
|
|
90
|
+
return (
|
|
91
|
+
<View style={[arrowS.wrap, hWrap('top')]}>
|
|
92
|
+
<View style={{ position: 'relative', width: s1 * 2, height: s1, alignItems: 'center' }}>
|
|
93
|
+
<View style={{ position: 'absolute', top: 0, width: 0, height: 0, borderStyle: 'solid', borderLeftWidth: s1, borderRightWidth: s1, borderBottomWidth: s1, borderTopWidth: 0, borderLeftColor: 'transparent', borderRightColor: 'transparent', borderBottomColor: borderColor }} />
|
|
94
|
+
<View style={{ position: 'absolute', top: 1, width: 0, height: 0, borderStyle: 'solid', borderLeftWidth: size, borderRightWidth: size, borderBottomWidth: size, borderTopWidth: 0, borderLeftColor: 'transparent', borderRightColor: 'transparent', borderBottomColor: color }} />
|
|
95
|
+
</View>
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (placement === 'top' || placement === 'above') {
|
|
100
|
+
// bubble above anchor → arrow at BOTTOM pointing ▼ down
|
|
101
|
+
return (
|
|
102
|
+
<View style={[arrowS.wrap, hWrap('bottom')]}>
|
|
103
|
+
<View style={{ position: 'relative', width: s1 * 2, height: s1, alignItems: 'center' }}>
|
|
104
|
+
<View style={{ position: 'absolute', top: 0, width: 0, height: 0, borderStyle: 'solid', borderLeftWidth: s1, borderRightWidth: s1, borderTopWidth: s1, borderBottomWidth: 0, borderLeftColor: 'transparent', borderRightColor: 'transparent', borderTopColor: borderColor }} />
|
|
105
|
+
<View style={{ position: 'absolute', top: 0, width: 0, height: 0, borderStyle: 'solid', borderLeftWidth: size, borderRightWidth: size, borderTopWidth: size, borderBottomWidth: 0, borderLeftColor: 'transparent', borderRightColor: 'transparent', borderTopColor: color }} />
|
|
106
|
+
</View>
|
|
107
|
+
</View>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (placement === 'right') {
|
|
111
|
+
// bubble right of anchor → arrow at LEFT pointing ◀ left
|
|
112
|
+
return (
|
|
113
|
+
<View style={[arrowS.wrap, vWrap('left')]}>
|
|
114
|
+
<View style={{ position: 'relative', width: s1, height: s1 * 2, justifyContent: 'center' }}>
|
|
115
|
+
<View style={{ position: 'absolute', left: 0, width: 0, height: 0, borderStyle: 'solid', borderTopWidth: s1, borderBottomWidth: s1, borderRightWidth: s1, borderLeftWidth: 0, borderTopColor: 'transparent', borderBottomColor: 'transparent', borderRightColor: borderColor }} />
|
|
116
|
+
<View style={{ position: 'absolute', left: 1, width: 0, height: 0, borderStyle: 'solid', borderTopWidth: size, borderBottomWidth: size, borderRightWidth: size, borderLeftWidth: 0, borderTopColor: 'transparent', borderBottomColor: 'transparent', borderRightColor: color }} />
|
|
117
|
+
</View>
|
|
118
|
+
</View>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (placement === 'left') {
|
|
122
|
+
// bubble left of anchor → arrow at RIGHT pointing ▶ right
|
|
123
|
+
return (
|
|
124
|
+
<View style={[arrowS.wrap, vWrap('right')]}>
|
|
125
|
+
<View style={{ position: 'relative', width: s1, height: s1 * 2, justifyContent: 'center' }}>
|
|
126
|
+
<View style={{ position: 'absolute', right: 0, width: 0, height: 0, borderStyle: 'solid', borderTopWidth: s1, borderBottomWidth: s1, borderLeftWidth: s1, borderRightWidth: 0, borderTopColor: 'transparent', borderBottomColor: 'transparent', borderLeftColor: borderColor }} />
|
|
127
|
+
<View style={{ position: 'absolute', right: 1, width: 0, height: 0, borderStyle: 'solid', borderTopWidth: size, borderBottomWidth: size, borderLeftWidth: size, borderRightWidth: 0, borderTopColor: 'transparent', borderBottomColor: 'transparent', borderLeftColor: color }} />
|
|
128
|
+
</View>
|
|
129
|
+
</View>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const arrowS = StyleSheet.create({
|
|
136
|
+
wrap: { position: 'absolute', alignItems: 'center', justifyContent: 'center' },
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// ─── Arrow offset helper ──────────────────────────────────────────────────────
|
|
140
|
+
// Returns the pixel distance from the start of the bubble side (left for
|
|
141
|
+
// top/bottom, top for left/right) to where the arrow tip should point,
|
|
142
|
+
// clamped so the arrow stays inside the bubble's rounded corners.
|
|
143
|
+
|
|
144
|
+
function calcArrowOffset(
|
|
145
|
+
placement: string,
|
|
146
|
+
layout: AnchorLayout,
|
|
147
|
+
floatPos: FloatPos,
|
|
148
|
+
bubbleW: number,
|
|
149
|
+
bubbleH: number,
|
|
150
|
+
cornerRadius: number,
|
|
151
|
+
arrowSize: number,
|
|
152
|
+
): number {
|
|
153
|
+
const minPad = cornerRadius + arrowSize + 2;
|
|
154
|
+
const isHoriz = placement === 'top' || placement === 'bottom' || placement === 'above' || placement === 'below';
|
|
155
|
+
if (isHoriz) {
|
|
156
|
+
const anchorCenterX = layout.pageX + layout.width / 2;
|
|
157
|
+
const raw = anchorCenterX - floatPos.x;
|
|
158
|
+
return Math.max(minPad, Math.min(bubbleW - minPad, raw));
|
|
159
|
+
}
|
|
160
|
+
const anchorCenterY = layout.pageY + layout.height / 2;
|
|
161
|
+
const raw = anchorCenterY - floatPos.y;
|
|
162
|
+
return Math.max(minPad, Math.min(bubbleH - minPad, raw));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ─── Shared action helpers ────────────────────────────────────────────────────
|
|
166
|
+
|
|
167
|
+
function ActionButton({
|
|
168
|
+
action,
|
|
169
|
+
btnPrimaryBg,
|
|
170
|
+
btnPrimaryText,
|
|
171
|
+
btnGhostText,
|
|
172
|
+
onPress,
|
|
173
|
+
}: {
|
|
174
|
+
action: Action;
|
|
175
|
+
btnPrimaryBg: string;
|
|
176
|
+
btnPrimaryText: string;
|
|
177
|
+
btnGhostText: string;
|
|
178
|
+
onPress: () => void;
|
|
179
|
+
}) {
|
|
180
|
+
const isPrimary = action.style === 'primary';
|
|
181
|
+
const fontFamily = Digia.fontFamily;
|
|
182
|
+
return (
|
|
183
|
+
<Pressable
|
|
184
|
+
onPress={onPress}
|
|
185
|
+
style={[s.button, isPrimary && { backgroundColor: btnPrimaryBg }]}
|
|
186
|
+
>
|
|
187
|
+
<Text style={{ color: isPrimary ? btnPrimaryText : btnGhostText, fontSize: 13, fontWeight: '600', fontFamily }}>
|
|
188
|
+
{action.label}
|
|
189
|
+
</Text>
|
|
190
|
+
</Pressable>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ─── Tooltip overlay ──────────────────────────────────────────────────────────
|
|
195
|
+
// Rendered WITHOUT a Modal so sticky tooltips do not block underlying scrolls.
|
|
196
|
+
// DigiaHost must be placed at the app root level (after NavigationContainer)
|
|
197
|
+
// for absoluteFill to cover the full screen.
|
|
198
|
+
|
|
199
|
+
function TooltipOverlay({
|
|
200
|
+
request,
|
|
201
|
+
config,
|
|
202
|
+
}: {
|
|
203
|
+
request: DigiaGuideRequest;
|
|
204
|
+
config: TooltipConfig;
|
|
205
|
+
}) {
|
|
206
|
+
const [stepIndex, setStepIndex] = useState(0);
|
|
207
|
+
const [layout, setLayout] = useState<AnchorLayout | null>(null);
|
|
208
|
+
const [floatPos, setFloatPos] = useState<FloatPos | null>(null);
|
|
209
|
+
const [resolvedPlacement, setResolvedPlacement] = useState<string>('bottom');
|
|
210
|
+
const [floatingSize, setFloatingSize] = useState<{ w: number; h: number } | null>(null);
|
|
211
|
+
const step = config.steps[stepIndex];
|
|
212
|
+
const { width: screenW } = useWindowDimensions();
|
|
213
|
+
const opacityAnim = useRef(new Animated.Value(1)).current;
|
|
214
|
+
const pendingFadeIn = useRef(false);
|
|
215
|
+
const fontFamily = Digia.fontFamily;
|
|
216
|
+
|
|
217
|
+
const arrowSize = step.arrowSize ?? 8;
|
|
218
|
+
const showArrow = step.showArrow !== false;
|
|
219
|
+
const gap = showArrow ? arrowSize + 4 : 8;
|
|
220
|
+
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
setLayout(null);
|
|
223
|
+
setFloatPos(null);
|
|
224
|
+
if (__DEV__) console.log(`[Digia] guide waiting for anchor key="${step.anchorKey}"`);
|
|
225
|
+
return digiaAnchorRegistry.subscribe(step.anchorKey, (l) => {
|
|
226
|
+
if (__DEV__) console.log(`[Digia] anchor resolved key="${step.anchorKey}"`, l);
|
|
227
|
+
setLayout(l);
|
|
228
|
+
});
|
|
229
|
+
}, [step.anchorKey]);
|
|
230
|
+
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
if (!layout || !floatingSize) return;
|
|
233
|
+
const tooltipW = Math.min(step.maxWidth, screenW - 32);
|
|
234
|
+
const fpPlacement = (step.placement === 'auto' ? 'bottom' : step.placement) as any;
|
|
235
|
+
computePosition(
|
|
236
|
+
makeVirtualRef(layout),
|
|
237
|
+
{ w: Math.min(tooltipW, floatingSize.w), h: floatingSize.h },
|
|
238
|
+
{
|
|
239
|
+
platform: rnCorePlatform as any,
|
|
240
|
+
placement: fpPlacement,
|
|
241
|
+
middleware: [offset(gap), flip(), shift({ padding: 16 })],
|
|
242
|
+
},
|
|
243
|
+
).then(({ x, y, placement }) => {
|
|
244
|
+
setFloatPos({ x, y });
|
|
245
|
+
setResolvedPlacement(placement as string);
|
|
246
|
+
});
|
|
247
|
+
}, [layout, floatingSize, step.placement, step.maxWidth, screenW, gap]);
|
|
248
|
+
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
if (floatPos && pendingFadeIn.current) {
|
|
251
|
+
pendingFadeIn.current = false;
|
|
252
|
+
Animated.timing(opacityAnim, { toValue: 1, duration: 180, useNativeDriver: true }).start();
|
|
253
|
+
}
|
|
254
|
+
}, [floatPos, opacityAnim]);
|
|
255
|
+
|
|
256
|
+
// Fire viewed/step_viewed when the step renders.
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
const isMultiStep = config.steps.length > 1;
|
|
259
|
+
if (stepIndex === 0) {
|
|
260
|
+
request.onExperienceEvent({ type: 'viewed', stepIndex: 0, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip' });
|
|
261
|
+
}
|
|
262
|
+
if (isMultiStep) {
|
|
263
|
+
request.onExperienceEvent({ type: 'step_viewed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip' });
|
|
264
|
+
}
|
|
265
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
266
|
+
}, [stepIndex]);
|
|
267
|
+
|
|
268
|
+
// Closes guide without firing analytics — used after CTA actions have already fired clicked events.
|
|
269
|
+
const closeFromCTA = useCallback(() => {
|
|
270
|
+
Animated.timing(opacityAnim, { toValue: 0, duration: 150, useNativeDriver: true }).start(() => {
|
|
271
|
+
digiaGuideController.cancel(request.payloadId);
|
|
272
|
+
});
|
|
273
|
+
}, [opacityAnim, request]);
|
|
274
|
+
|
|
275
|
+
// Fires dismissed analytics then closes — used for non-CTA dismissals (scrim, back gesture).
|
|
276
|
+
const dismiss = useCallback((reason: DismissReason = 'scrim_tap') => {
|
|
277
|
+
Animated.timing(opacityAnim, { toValue: 0, duration: 150, useNativeDriver: true }).start(() => {
|
|
278
|
+
const isMultiStep = config.steps.length > 1;
|
|
279
|
+
request.onExperienceEvent({ type: 'dismissed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip', dismissReason: reason });
|
|
280
|
+
if (isMultiStep) {
|
|
281
|
+
request.onExperienceEvent({ type: 'step_dismissed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip', dismissReason: reason });
|
|
282
|
+
}
|
|
283
|
+
digiaGuideController.cancel(request.payloadId);
|
|
284
|
+
});
|
|
285
|
+
}, [request, opacityAnim, step, config, stepIndex]);
|
|
286
|
+
|
|
287
|
+
const stepTo = useCallback((newIndex: number | null) => {
|
|
288
|
+
Animated.timing(opacityAnim, { toValue: 0, duration: 150, useNativeDriver: true }).start(() => {
|
|
289
|
+
if (newIndex === null) {
|
|
290
|
+
digiaGuideController.cancel(request.payloadId);
|
|
291
|
+
} else {
|
|
292
|
+
pendingFadeIn.current = true;
|
|
293
|
+
setStepIndex(newIndex);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}, [opacityAnim, request]);
|
|
297
|
+
|
|
298
|
+
const next = useCallback(() => stepTo(stepIndex < config.steps.length - 1 ? stepIndex + 1 : null), [stepIndex, config.steps.length, stepTo]);
|
|
299
|
+
const prev = useCallback(() => { if (stepIndex > 0) stepTo(stepIndex - 1); }, [stepIndex, stepTo]);
|
|
300
|
+
|
|
301
|
+
const actionCallbacks = useCallback((): ActionCallbacks => ({
|
|
302
|
+
onNext: next,
|
|
303
|
+
onBack: prev,
|
|
304
|
+
onDismissSelf: closeFromCTA,
|
|
305
|
+
onDismissAll: closeFromCTA,
|
|
306
|
+
}), [next, prev, closeFromCTA]);
|
|
307
|
+
|
|
308
|
+
const tooltipW = Math.min(step.maxWidth, screenW - 32);
|
|
309
|
+
|
|
310
|
+
const arrowOffset = (showArrow && floatPos && layout && floatingSize)
|
|
311
|
+
? calcArrowOffset(resolvedPlacement, layout, floatPos, tooltipW, floatingSize.h, step.cornerRadius, arrowSize)
|
|
312
|
+
: undefined;
|
|
313
|
+
|
|
314
|
+
const handleBackdropPress = useCallback(() => {
|
|
315
|
+
const behavior = config.outsideTapBehavior ?? 'next';
|
|
316
|
+
if (behavior === 'nothing') return;
|
|
317
|
+
if (behavior === 'next') next();
|
|
318
|
+
if (behavior === 'dismiss') dismiss();
|
|
319
|
+
}, [config.outsideTapBehavior, next, dismiss]);
|
|
320
|
+
|
|
321
|
+
return (
|
|
322
|
+
<Modal transparent statusBarTranslucent animationType="none" visible>
|
|
323
|
+
<Animated.View style={[StyleSheet.absoluteFill, { opacity: opacityAnim }]}>
|
|
324
|
+
{/* Full-screen backdrop: blocks all touches (scroll, tap) */}
|
|
325
|
+
<Pressable style={StyleSheet.absoluteFill} onPress={handleBackdropPress} />
|
|
326
|
+
{floatPos ? (
|
|
327
|
+
// Bubble as Pressable so tapping the bubble body also advances
|
|
328
|
+
<Pressable
|
|
329
|
+
onLayout={(e) => {
|
|
330
|
+
const { width, height } = e.nativeEvent.layout;
|
|
331
|
+
if (floatingSize?.w !== width || floatingSize?.h !== height) {
|
|
332
|
+
setFloatingSize({ w: width, h: height });
|
|
333
|
+
}
|
|
334
|
+
}}
|
|
335
|
+
onPress={handleBackdropPress}
|
|
336
|
+
style={[
|
|
337
|
+
s.tooltipBubble,
|
|
338
|
+
{
|
|
339
|
+
left: floatPos.x,
|
|
340
|
+
top: floatPos.y,
|
|
341
|
+
width: tooltipW,
|
|
342
|
+
backgroundColor: step.backgroundColor,
|
|
343
|
+
borderRadius: step.cornerRadius,
|
|
344
|
+
borderWidth: step.borderWidth,
|
|
345
|
+
borderColor: step.borderColor,
|
|
346
|
+
padding: step.padding,
|
|
347
|
+
},
|
|
348
|
+
step.shadow && s.shadow,
|
|
349
|
+
]}
|
|
350
|
+
>
|
|
351
|
+
{showArrow && (
|
|
352
|
+
<GuideArrow
|
|
353
|
+
placement={resolvedPlacement}
|
|
354
|
+
color={step.arrowColor ?? step.backgroundColor}
|
|
355
|
+
borderColor={step.arrowBorderColor ?? step.borderColor}
|
|
356
|
+
size={arrowSize}
|
|
357
|
+
arrowOffset={arrowOffset}
|
|
358
|
+
/>
|
|
359
|
+
)}
|
|
360
|
+
<Text style={{ color: step.titleColor, fontSize: step.titleSize, fontWeight: step.titleWeight, fontFamily }}>
|
|
361
|
+
{step.title}
|
|
362
|
+
</Text>
|
|
363
|
+
{!!step.body && (
|
|
364
|
+
<Text style={{ marginTop: 4, color: step.bodyColor, fontSize: step.bodySize, fontFamily }}>
|
|
365
|
+
{step.body}
|
|
366
|
+
</Text>
|
|
367
|
+
)}
|
|
368
|
+
<View style={s.actionRow}>
|
|
369
|
+
{step.actions.map((action, i) => (
|
|
370
|
+
<ActionButton
|
|
371
|
+
key={i}
|
|
372
|
+
action={action}
|
|
373
|
+
btnPrimaryBg={step.buttonPrimaryBackgroundColor}
|
|
374
|
+
btnPrimaryText={step.buttonPrimaryTextColor}
|
|
375
|
+
btnGhostText={step.buttonGhostTextColor}
|
|
376
|
+
onPress={() => {
|
|
377
|
+
const isMultiStep = config.steps.length > 1;
|
|
378
|
+
const isLastStep = stepIndex === config.steps.length - 1;
|
|
379
|
+
const actionUrl = 'url' in action ? (action as { url: string }).url : undefined;
|
|
380
|
+
request.onExperienceEvent({ type: 'clicked', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip', ctaLabel: action.label, actionType: action.type, actionUrl });
|
|
381
|
+
if (isMultiStep) {
|
|
382
|
+
request.onExperienceEvent({ type: 'step_clicked', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip', ctaLabel: action.label, actionType: action.type, actionUrl });
|
|
383
|
+
}
|
|
384
|
+
if (isMultiStep && isLastStep && action.type !== 'back') {
|
|
385
|
+
request.onExperienceEvent({ type: 'completed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'tooltip' });
|
|
386
|
+
}
|
|
387
|
+
void digiaActionHandler.execute(action, {
|
|
388
|
+
campaign_id: request.payloadId,
|
|
389
|
+
campaign_key: request.campaignKey,
|
|
390
|
+
campaign_type: 'guide',
|
|
391
|
+
source: { kind: 'button', button_label: action.label },
|
|
392
|
+
step_index: stepIndex,
|
|
393
|
+
step_total: config.steps.length,
|
|
394
|
+
}, actionCallbacks());
|
|
395
|
+
}}
|
|
396
|
+
/>
|
|
397
|
+
))}
|
|
398
|
+
</View>
|
|
399
|
+
</Pressable>
|
|
400
|
+
) : (
|
|
401
|
+
// Off-screen measurement pass to determine bubble size before positioning.
|
|
402
|
+
<View
|
|
403
|
+
pointerEvents="none"
|
|
404
|
+
onLayout={(e) => setFloatingSize({ w: e.nativeEvent.layout.width, h: e.nativeEvent.layout.height })}
|
|
405
|
+
style={[s.tooltipBubble, { left: -9999, top: -9999, width: tooltipW, padding: step.padding }]}
|
|
406
|
+
>
|
|
407
|
+
<Text style={{ fontSize: step.titleSize, fontFamily }}>{step.title}</Text>
|
|
408
|
+
{!!step.body && <Text style={{ fontSize: step.bodySize, fontFamily }}>{step.body}</Text>}
|
|
409
|
+
<View style={s.actionRow}>
|
|
410
|
+
{step.actions.map((a, i) => (
|
|
411
|
+
<View key={i} style={s.button}>
|
|
412
|
+
<Text style={{ fontSize: 13, fontFamily }}>{a.label}</Text>
|
|
413
|
+
</View>
|
|
414
|
+
))}
|
|
415
|
+
</View>
|
|
416
|
+
</View>
|
|
417
|
+
)}
|
|
418
|
+
</Animated.View>
|
|
419
|
+
</Modal>
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// ─── Spotlight overlay ────────────────────────────────────────────────────────
|
|
424
|
+
|
|
425
|
+
function buildCutoutPath(
|
|
426
|
+
x: number, y: number, w: number, h: number,
|
|
427
|
+
radius: number, shape: string,
|
|
428
|
+
): string {
|
|
429
|
+
if (shape === 'circle') {
|
|
430
|
+
const cx = x + w / 2;
|
|
431
|
+
const cy = y + h / 2;
|
|
432
|
+
const r = Math.max(w, h) / 2;
|
|
433
|
+
return `M${cx - r},${cy} a${r},${r} 0 1,0 ${r * 2},0 a${r},${r} 0 1,0 -${r * 2},0 Z`;
|
|
434
|
+
}
|
|
435
|
+
if (shape === 'pill') {
|
|
436
|
+
const r = h / 2;
|
|
437
|
+
return `M${x + r},${y} L${x + w - r},${y} Q${x + w},${y} ${x + w},${y + r} L${x + w},${y + h - r} Q${x + w},${y + h} ${x + w - r},${y + h} L${x + r},${y + h} Q${x},${y + h} ${x},${y + h - r} L${x},${y + r} Q${x},${y} ${x + r},${y} Z`;
|
|
438
|
+
}
|
|
439
|
+
const r = Math.max(0, radius);
|
|
440
|
+
if (r === 0) {
|
|
441
|
+
return `M${x},${y} L${x + w},${y} L${x + w},${y + h} L${x},${y + h} Z`;
|
|
442
|
+
}
|
|
443
|
+
return `M${x + r},${y} L${x + w - r},${y} Q${x + w},${y} ${x + w},${y + r} L${x + w},${y + h - r} Q${x + w},${y + h} ${x + w - r},${y + h} L${x + r},${y + h} Q${x},${y + h} ${x},${y + h - r} L${x},${y + r} Q${x},${y} ${x + r},${y} Z`;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function SpotlightCallout({
|
|
447
|
+
step,
|
|
448
|
+
layout,
|
|
449
|
+
onActionPress,
|
|
450
|
+
}: {
|
|
451
|
+
step: SpotlightStep;
|
|
452
|
+
layout: AnchorLayout;
|
|
453
|
+
onActionPress: (action: Action) => void;
|
|
454
|
+
}) {
|
|
455
|
+
const { width: screenW } = useWindowDimensions();
|
|
456
|
+
const [floatPos, setFloatPos] = useState<FloatPos | null>(null);
|
|
457
|
+
const [resolvedPlacement, setResolvedPlacement] = useState<string>('below');
|
|
458
|
+
const [floatingSize, setFloatingSize] = useState<{ w: number; h: number } | null>(null);
|
|
459
|
+
const calloutW = Math.min(step.calloutMaxWidth, screenW - 32);
|
|
460
|
+
|
|
461
|
+
const arrowSize = step.arrowSize ?? 8;
|
|
462
|
+
const showArrow = step.showArrow !== false;
|
|
463
|
+
const gap = (step.calloutGap ?? 8) + (showArrow ? arrowSize : 0);
|
|
464
|
+
const fontFamily = Digia.fontFamily;
|
|
465
|
+
|
|
466
|
+
useEffect(() => {
|
|
467
|
+
if (!floatingSize) return;
|
|
468
|
+
const fpPlacement = (
|
|
469
|
+
step.calloutPosition === 'above' ? 'top'
|
|
470
|
+
: step.calloutPosition === 'below' ? 'bottom'
|
|
471
|
+
: step.calloutPosition === 'auto' ? 'bottom'
|
|
472
|
+
: step.calloutPosition
|
|
473
|
+
) as any;
|
|
474
|
+
computePosition(
|
|
475
|
+
makeVirtualRef(layout, step.highlightPadding),
|
|
476
|
+
{ w: Math.min(calloutW, floatingSize.w), h: floatingSize.h },
|
|
477
|
+
{
|
|
478
|
+
platform: rnCorePlatform as any,
|
|
479
|
+
placement: fpPlacement,
|
|
480
|
+
middleware: [offset(gap), flip(), shift({ padding: 16 })],
|
|
481
|
+
},
|
|
482
|
+
).then(({ x, y, placement }) => {
|
|
483
|
+
console.log('[Digia:spotlight] floatPos=', { x, y }, 'resolved=', placement);
|
|
484
|
+
setFloatPos({ x, y });
|
|
485
|
+
setResolvedPlacement(placement as string);
|
|
486
|
+
});
|
|
487
|
+
}, [layout, floatingSize, step.calloutPosition, calloutW, step.highlightPadding, gap]);
|
|
488
|
+
|
|
489
|
+
// Compute arrow offset: point arrow tip at anchor center.
|
|
490
|
+
const arrowOffset = (showArrow && floatPos && floatingSize)
|
|
491
|
+
? calcArrowOffset(resolvedPlacement, layout, floatPos, calloutW, floatingSize.h, step.calloutCornerRadius, arrowSize)
|
|
492
|
+
: undefined;
|
|
493
|
+
|
|
494
|
+
const calloutStyle = {
|
|
495
|
+
backgroundColor: step.calloutBackgroundColor,
|
|
496
|
+
borderRadius: step.calloutCornerRadius,
|
|
497
|
+
padding: step.calloutPadding,
|
|
498
|
+
borderWidth: step.calloutBorderWidth,
|
|
499
|
+
borderColor: step.calloutBorderColor,
|
|
500
|
+
width: calloutW,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
if (!floatPos) {
|
|
504
|
+
return (
|
|
505
|
+
<View
|
|
506
|
+
pointerEvents="none"
|
|
507
|
+
onLayout={(e) => setFloatingSize({ w: e.nativeEvent.layout.width, h: e.nativeEvent.layout.height })}
|
|
508
|
+
style={[calloutStyle, { position: 'absolute', left: -9999, top: -9999 }]}
|
|
509
|
+
>
|
|
510
|
+
<Text style={{ fontSize: step.titleSize, fontFamily }}>{step.title}</Text>
|
|
511
|
+
{!!step.body && <Text style={{ marginTop: 4, fontSize: step.bodySize, fontFamily }}>{step.body}</Text>}
|
|
512
|
+
<View style={s.actionRow}>
|
|
513
|
+
{step.actions.map((a, i) => (
|
|
514
|
+
<View key={i} style={s.button}>
|
|
515
|
+
<Text style={{ fontSize: 13, fontFamily }}>{a.label}</Text>
|
|
516
|
+
</View>
|
|
517
|
+
))}
|
|
518
|
+
</View>
|
|
519
|
+
</View>
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
return (
|
|
524
|
+
<View
|
|
525
|
+
style={[
|
|
526
|
+
calloutStyle,
|
|
527
|
+
{ position: 'absolute', left: floatPos.x, top: floatPos.y },
|
|
528
|
+
step.calloutShadow && s.shadow,
|
|
529
|
+
]}
|
|
530
|
+
>
|
|
531
|
+
{showArrow && (
|
|
532
|
+
<GuideArrow
|
|
533
|
+
placement={resolvedPlacement}
|
|
534
|
+
color={step.arrowColor ?? step.calloutBackgroundColor}
|
|
535
|
+
borderColor={step.arrowBorderColor ?? step.calloutBorderColor}
|
|
536
|
+
size={arrowSize}
|
|
537
|
+
arrowOffset={arrowOffset}
|
|
538
|
+
/>
|
|
539
|
+
)}
|
|
540
|
+
<Text style={{ color: step.titleColor, fontSize: step.titleSize, fontWeight: step.titleWeight, fontFamily }}>
|
|
541
|
+
{step.title}
|
|
542
|
+
</Text>
|
|
543
|
+
{!!step.body && (
|
|
544
|
+
<Text style={{ marginTop: 4, color: step.bodyColor, fontSize: step.bodySize, fontFamily }}>
|
|
545
|
+
{step.body}
|
|
546
|
+
</Text>
|
|
547
|
+
)}
|
|
548
|
+
<View style={s.actionRow}>
|
|
549
|
+
{step.actions.map((action, i) => (
|
|
550
|
+
<ActionButton
|
|
551
|
+
key={i}
|
|
552
|
+
action={action}
|
|
553
|
+
btnPrimaryBg={step.buttonPrimaryBackgroundColor}
|
|
554
|
+
btnPrimaryText={step.buttonPrimaryTextColor}
|
|
555
|
+
btnGhostText={step.buttonGhostTextColor}
|
|
556
|
+
onPress={() => { onActionPress(action); }}
|
|
557
|
+
/>
|
|
558
|
+
))}
|
|
559
|
+
</View>
|
|
560
|
+
</View>
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function SpotlightOverlay({
|
|
565
|
+
request,
|
|
566
|
+
config,
|
|
567
|
+
}: {
|
|
568
|
+
request: DigiaGuideRequest;
|
|
569
|
+
config: SpotlightConfig;
|
|
570
|
+
}) {
|
|
571
|
+
const [stepIndex, setStepIndex] = useState(0);
|
|
572
|
+
const [layout, setLayout] = useState<AnchorLayout | null>(null);
|
|
573
|
+
const step = config.steps[stepIndex];
|
|
574
|
+
const { width: screenW, height: screenH } = useWindowDimensions();
|
|
575
|
+
const opacityAnim = useRef(new Animated.Value(1)).current;
|
|
576
|
+
const pendingFadeIn = useRef(false);
|
|
577
|
+
|
|
578
|
+
useEffect(() => {
|
|
579
|
+
setLayout(null);
|
|
580
|
+
return digiaAnchorRegistry.subscribe(step.anchorKey, (l) => {
|
|
581
|
+
setLayout(l);
|
|
582
|
+
});
|
|
583
|
+
}, [step.anchorKey]);
|
|
584
|
+
|
|
585
|
+
useEffect(() => {
|
|
586
|
+
if (layout && pendingFadeIn.current) {
|
|
587
|
+
pendingFadeIn.current = false;
|
|
588
|
+
Animated.timing(opacityAnim, { toValue: 1, duration: 180, useNativeDriver: true }).start();
|
|
589
|
+
}
|
|
590
|
+
}, [layout, opacityAnim]);
|
|
591
|
+
|
|
592
|
+
// Fire viewed/step_viewed when the step renders.
|
|
593
|
+
useEffect(() => {
|
|
594
|
+
const isMultiStep = config.steps.length > 1;
|
|
595
|
+
if (stepIndex === 0) {
|
|
596
|
+
request.onExperienceEvent({ type: 'viewed', stepIndex: 0, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight' });
|
|
597
|
+
}
|
|
598
|
+
if (isMultiStep) {
|
|
599
|
+
request.onExperienceEvent({ type: 'step_viewed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight' });
|
|
600
|
+
}
|
|
601
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
602
|
+
}, [stepIndex]);
|
|
603
|
+
|
|
604
|
+
const closeFromCTA = useCallback(() => {
|
|
605
|
+
Animated.timing(opacityAnim, { toValue: 0, duration: 150, useNativeDriver: true }).start(() => {
|
|
606
|
+
digiaGuideController.cancel(request.payloadId);
|
|
607
|
+
});
|
|
608
|
+
}, [opacityAnim, request]);
|
|
609
|
+
|
|
610
|
+
const dismiss = useCallback((reason: DismissReason = 'scrim_tap') => {
|
|
611
|
+
Animated.timing(opacityAnim, { toValue: 0, duration: 150, useNativeDriver: true }).start(() => {
|
|
612
|
+
const isMultiStep = config.steps.length > 1;
|
|
613
|
+
request.onExperienceEvent({ type: 'dismissed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight', dismissReason: reason });
|
|
614
|
+
if (isMultiStep) {
|
|
615
|
+
request.onExperienceEvent({ type: 'step_dismissed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight', dismissReason: reason });
|
|
616
|
+
}
|
|
617
|
+
digiaGuideController.cancel(request.payloadId);
|
|
618
|
+
});
|
|
619
|
+
}, [request, opacityAnim, step, config, stepIndex]);
|
|
620
|
+
|
|
621
|
+
const stepTo = useCallback((newIndex: number | null) => {
|
|
622
|
+
Animated.timing(opacityAnim, { toValue: 0, duration: 150, useNativeDriver: true }).start(() => {
|
|
623
|
+
if (newIndex === null) {
|
|
624
|
+
digiaGuideController.cancel(request.payloadId);
|
|
625
|
+
} else {
|
|
626
|
+
pendingFadeIn.current = true;
|
|
627
|
+
setStepIndex(newIndex);
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}, [opacityAnim, request]);
|
|
631
|
+
|
|
632
|
+
const next = useCallback(() => stepTo(stepIndex < config.steps.length - 1 ? stepIndex + 1 : null), [stepIndex, config.steps.length, stepTo]);
|
|
633
|
+
const prev = useCallback(() => { if (stepIndex > 0) stepTo(stepIndex - 1); }, [stepIndex, stepTo]);
|
|
634
|
+
|
|
635
|
+
const actionCallbacks = useCallback((): ActionCallbacks => ({
|
|
636
|
+
onNext: next,
|
|
637
|
+
onBack: prev,
|
|
638
|
+
onDismissSelf: closeFromCTA,
|
|
639
|
+
onDismissAll: closeFromCTA,
|
|
640
|
+
}), [next, prev, closeFromCTA]);
|
|
641
|
+
|
|
642
|
+
const handleActionPress = useCallback((action: Action) => {
|
|
643
|
+
const isMultiStep = config.steps.length > 1;
|
|
644
|
+
const isLastStep = stepIndex === config.steps.length - 1;
|
|
645
|
+
const actionUrl = 'url' in action ? (action as { url: string }).url : undefined;
|
|
646
|
+
request.onExperienceEvent({ type: 'clicked', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight', ctaLabel: action.label, actionType: action.type, actionUrl });
|
|
647
|
+
if (isMultiStep) {
|
|
648
|
+
request.onExperienceEvent({ type: 'step_clicked', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight', ctaLabel: action.label, actionType: action.type, actionUrl });
|
|
649
|
+
}
|
|
650
|
+
if (isMultiStep && isLastStep && action.type !== 'back') {
|
|
651
|
+
request.onExperienceEvent({ type: 'completed', stepIndex, stepTotal: config.steps.length, anchorKey: step.anchorKey, displayStyle: 'spotlight' });
|
|
652
|
+
}
|
|
653
|
+
digiaActionHandler.execute(action, {
|
|
654
|
+
campaign_id: request.payloadId,
|
|
655
|
+
campaign_key: request.campaignKey,
|
|
656
|
+
campaign_type: 'guide',
|
|
657
|
+
source: { kind: 'button', button_label: action.label },
|
|
658
|
+
step_index: stepIndex,
|
|
659
|
+
step_total: config.steps.length,
|
|
660
|
+
}, actionCallbacks());
|
|
661
|
+
}, [request, stepIndex, config, step, actionCallbacks]);
|
|
662
|
+
|
|
663
|
+
const handleBackdropPress = useCallback(() => {
|
|
664
|
+
const behavior = config.outsideTapBehavior ?? 'next';
|
|
665
|
+
if (behavior === 'nothing') return;
|
|
666
|
+
if (behavior === 'next') next();
|
|
667
|
+
if (behavior === 'dismiss') dismiss('scrim_tap');
|
|
668
|
+
}, [config.outsideTapBehavior, next, dismiss]);
|
|
669
|
+
|
|
670
|
+
const pad = step.highlightPadding;
|
|
671
|
+
const cutoutX = layout ? layout.pageX - pad : 0;
|
|
672
|
+
const cutoutY = layout ? layout.pageY - pad : 0;
|
|
673
|
+
const cutoutW = layout ? layout.width + pad * 2 : 0;
|
|
674
|
+
const cutoutH = layout ? layout.height + pad * 2 : 0;
|
|
675
|
+
const screenPath = `M0,0 L${screenW},0 L${screenW},${screenH} L0,${screenH} Z`;
|
|
676
|
+
const cutoutPath = layout
|
|
677
|
+
? buildCutoutPath(cutoutX, cutoutY, cutoutW, cutoutH, step.highlightCornerRadius, step.highlightShape)
|
|
678
|
+
: '';
|
|
679
|
+
|
|
680
|
+
return (
|
|
681
|
+
<Modal transparent statusBarTranslucent animationType="none" visible>
|
|
682
|
+
<Animated.View style={[StyleSheet.absoluteFill, { opacity: opacityAnim }]} pointerEvents="box-none">
|
|
683
|
+
{layout && (
|
|
684
|
+
<>
|
|
685
|
+
<Svg
|
|
686
|
+
width={screenW}
|
|
687
|
+
height={screenH}
|
|
688
|
+
style={StyleSheet.absoluteFill}
|
|
689
|
+
pointerEvents="none"
|
|
690
|
+
>
|
|
691
|
+
<Path
|
|
692
|
+
fillRule="evenodd"
|
|
693
|
+
d={`${screenPath} ${cutoutPath}`}
|
|
694
|
+
fill={step.overlayColor}
|
|
695
|
+
fillOpacity={step.overlayOpacity}
|
|
696
|
+
/>
|
|
697
|
+
{step.highlightGlowWidth > 0 && (
|
|
698
|
+
<Path
|
|
699
|
+
d={cutoutPath}
|
|
700
|
+
fill="none"
|
|
701
|
+
stroke={step.highlightGlowColor}
|
|
702
|
+
strokeWidth={step.highlightGlowWidth}
|
|
703
|
+
/>
|
|
704
|
+
)}
|
|
705
|
+
</Svg>
|
|
706
|
+
{/* Backdrop with configurable outside-tap behaviour */}
|
|
707
|
+
<Pressable style={StyleSheet.absoluteFill} onPress={handleBackdropPress} />
|
|
708
|
+
<SpotlightCallout
|
|
709
|
+
step={step}
|
|
710
|
+
layout={layout}
|
|
711
|
+
onActionPress={handleActionPress}
|
|
712
|
+
/>
|
|
713
|
+
</>
|
|
714
|
+
)}
|
|
715
|
+
</Animated.View>
|
|
716
|
+
</Modal>
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// ─── Guide runtime dispatcher ─────────────────────────────────────────────────
|
|
721
|
+
|
|
722
|
+
function DigiaGuideRuntime() {
|
|
723
|
+
const [activeRequest, setActiveRequest] = useState<DigiaGuideRequest | null>(null);
|
|
724
|
+
|
|
725
|
+
useEffect(() => {
|
|
726
|
+
return digiaGuideController.subscribe((event) => {
|
|
727
|
+
if (event.type === 'cancel') {
|
|
728
|
+
setActiveRequest(null);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
setActiveRequest(event.request);
|
|
732
|
+
});
|
|
733
|
+
}, []);
|
|
734
|
+
|
|
735
|
+
if (!activeRequest) return null;
|
|
736
|
+
|
|
737
|
+
switch (activeRequest.config.templateType) {
|
|
738
|
+
case 'tooltip':
|
|
739
|
+
return <TooltipOverlay request={activeRequest} config={activeRequest.config} />;
|
|
740
|
+
case 'spotlight':
|
|
741
|
+
return <SpotlightOverlay request={activeRequest} config={activeRequest.config} />;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// ─── DigiaHost ────────────────────────────────────────────────────────────────
|
|
746
|
+
|
|
747
|
+
export function DigiaHost() {
|
|
748
|
+
return <DigiaGuideRuntime />;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// ─── Styles ───────────────────────────────────────────────────────────────────
|
|
752
|
+
|
|
753
|
+
const s = StyleSheet.create({
|
|
754
|
+
tooltipBubble: {
|
|
755
|
+
position: 'absolute',
|
|
756
|
+
},
|
|
757
|
+
shadow: {
|
|
758
|
+
shadowColor: '#000',
|
|
759
|
+
shadowOpacity: 0.15,
|
|
760
|
+
shadowRadius: 12,
|
|
761
|
+
shadowOffset: { width: 0, height: 4 },
|
|
762
|
+
elevation: 8,
|
|
763
|
+
},
|
|
764
|
+
actionRow: {
|
|
765
|
+
marginTop: 12,
|
|
766
|
+
flexDirection: 'row',
|
|
767
|
+
justifyContent: 'flex-end',
|
|
768
|
+
gap: 8,
|
|
769
|
+
},
|
|
770
|
+
button: {
|
|
771
|
+
minHeight: 32,
|
|
772
|
+
minWidth: 60,
|
|
773
|
+
alignItems: 'center',
|
|
774
|
+
justifyContent: 'center',
|
|
775
|
+
borderRadius: 8,
|
|
776
|
+
paddingHorizontal: 12,
|
|
777
|
+
},
|
|
778
|
+
});
|