rn-smart-tour 1.0.8 → 2.0.0-beta.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/LICENSE +21 -0
- package/README.md +240 -57
- package/lib/commonjs/compat.js +87 -0
- package/lib/commonjs/compat.js.map +1 -0
- package/lib/commonjs/core/TourEngine.js +450 -0
- package/lib/commonjs/core/TourEngine.js.map +1 -0
- package/lib/commonjs/core/controller.js +34 -0
- package/lib/commonjs/core/controller.js.map +1 -0
- package/lib/commonjs/core/measure.js +130 -0
- package/lib/commonjs/core/measure.js.map +1 -0
- package/lib/commonjs/core/store.js +39 -0
- package/lib/commonjs/core/store.js.map +1 -0
- package/lib/commonjs/index.js +109 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/TourOverlay.js +290 -0
- package/lib/commonjs/react/TourOverlay.js.map +1 -0
- package/lib/commonjs/react/TourProvider.js +62 -0
- package/lib/commonjs/react/TourProvider.js.map +1 -0
- package/lib/commonjs/react/TourScope.js +39 -0
- package/lib/commonjs/react/TourScope.js.map +1 -0
- package/lib/commonjs/react/TourScrollable.js +61 -0
- package/lib/commonjs/react/TourScrollable.js.map +1 -0
- package/lib/commonjs/react/TourTarget.js +51 -0
- package/lib/commonjs/react/TourTarget.js.map +1 -0
- package/lib/commonjs/react/context.js +15 -0
- package/lib/commonjs/react/context.js.map +1 -0
- package/lib/commonjs/react/hooks.js +81 -0
- package/lib/commonjs/react/hooks.js.map +1 -0
- package/lib/commonjs/react/placement.js +61 -0
- package/lib/commonjs/react/placement.js.map +1 -0
- package/lib/commonjs/react-navigation.js +80 -0
- package/lib/commonjs/react-navigation.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/compat.js +81 -0
- package/lib/module/compat.js.map +1 -0
- package/lib/module/core/TourEngine.js +446 -0
- package/lib/module/core/TourEngine.js.map +1 -0
- package/lib/module/core/controller.js +29 -0
- package/lib/module/core/controller.js.map +1 -0
- package/lib/module/core/measure.js +118 -0
- package/lib/module/core/measure.js.map +1 -0
- package/lib/module/core/store.js +34 -0
- package/lib/module/core/store.js.map +1 -0
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/TourOverlay.js +282 -0
- package/lib/module/react/TourOverlay.js.map +1 -0
- package/lib/module/react/TourProvider.js +55 -0
- package/lib/module/react/TourProvider.js.map +1 -0
- package/lib/module/react/TourScope.js +32 -0
- package/lib/module/react/TourScope.js.map +1 -0
- package/lib/module/react/TourScrollable.js +54 -0
- package/lib/module/react/TourScrollable.js.map +1 -0
- package/lib/module/react/TourTarget.js +44 -0
- package/lib/module/react/TourTarget.js.map +1 -0
- package/lib/module/react/context.js +11 -0
- package/lib/module/react/context.js.map +1 -0
- package/lib/module/react/hooks.js +73 -0
- package/lib/module/react/hooks.js.map +1 -0
- package/lib/module/react/placement.js +57 -0
- package/lib/module/react/placement.js.map +1 -0
- package/lib/module/react-navigation.js +74 -0
- package/lib/module/react-navigation.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/compat.d.ts +13 -0
- package/lib/typescript/commonjs/src/compat.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/core/TourEngine.d.ts +113 -0
- package/lib/typescript/commonjs/src/core/TourEngine.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/core/controller.d.ts +33 -0
- package/lib/typescript/commonjs/src/core/controller.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/core/measure.d.ts +26 -0
- package/lib/typescript/commonjs/src/core/measure.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/core/store.d.ts +9 -0
- package/lib/typescript/commonjs/src/core/store.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +17 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/TourOverlay.d.ts +17 -0
- package/lib/typescript/commonjs/src/react/TourOverlay.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/TourProvider.d.ts +27 -0
- package/lib/typescript/commonjs/src/react/TourProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/TourScope.d.ts +17 -0
- package/lib/typescript/commonjs/src/react/TourScope.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/TourScrollable.d.ts +25 -0
- package/lib/typescript/commonjs/src/react/TourScrollable.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/TourTarget.d.ts +13 -0
- package/lib/typescript/commonjs/src/react/TourTarget.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/context.d.ts +7 -0
- package/lib/typescript/commonjs/src/react/context.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/hooks.d.ts +12 -0
- package/lib/typescript/commonjs/src/react/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react/placement.d.ts +19 -0
- package/lib/typescript/commonjs/src/react/placement.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/react-navigation.d.ts +15 -0
- package/lib/typescript/commonjs/src/react-navigation.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +89 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/compat.d.ts +13 -0
- package/lib/typescript/module/src/compat.d.ts.map +1 -0
- package/lib/typescript/module/src/core/TourEngine.d.ts +113 -0
- package/lib/typescript/module/src/core/TourEngine.d.ts.map +1 -0
- package/lib/typescript/module/src/core/controller.d.ts +33 -0
- package/lib/typescript/module/src/core/controller.d.ts.map +1 -0
- package/lib/typescript/module/src/core/measure.d.ts +26 -0
- package/lib/typescript/module/src/core/measure.d.ts.map +1 -0
- package/lib/typescript/module/src/core/store.d.ts +9 -0
- package/lib/typescript/module/src/core/store.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +17 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/react/TourOverlay.d.ts +17 -0
- package/lib/typescript/module/src/react/TourOverlay.d.ts.map +1 -0
- package/lib/typescript/module/src/react/TourProvider.d.ts +27 -0
- package/lib/typescript/module/src/react/TourProvider.d.ts.map +1 -0
- package/lib/typescript/module/src/react/TourScope.d.ts +17 -0
- package/lib/typescript/module/src/react/TourScope.d.ts.map +1 -0
- package/lib/typescript/module/src/react/TourScrollable.d.ts +25 -0
- package/lib/typescript/module/src/react/TourScrollable.d.ts.map +1 -0
- package/lib/typescript/module/src/react/TourTarget.d.ts +13 -0
- package/lib/typescript/module/src/react/TourTarget.d.ts.map +1 -0
- package/lib/typescript/module/src/react/context.d.ts +7 -0
- package/lib/typescript/module/src/react/context.d.ts.map +1 -0
- package/lib/typescript/module/src/react/hooks.d.ts +12 -0
- package/lib/typescript/module/src/react/hooks.d.ts.map +1 -0
- package/lib/typescript/module/src/react/placement.d.ts +19 -0
- package/lib/typescript/module/src/react/placement.d.ts.map +1 -0
- package/lib/typescript/module/src/react-navigation.d.ts +15 -0
- package/lib/typescript/module/src/react-navigation.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +89 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/package.json +104 -12
- package/react-navigation/package.json +6 -0
- package/src/compat.ts +84 -0
- package/src/core/TourEngine.ts +483 -0
- package/src/core/controller.ts +43 -0
- package/src/core/measure.ts +129 -0
- package/src/core/store.ts +39 -0
- package/src/index.ts +16 -0
- package/src/react/TourOverlay.tsx +260 -0
- package/src/react/TourProvider.tsx +82 -0
- package/src/react/TourScope.tsx +33 -0
- package/src/react/TourScrollable.tsx +58 -0
- package/src/react/TourTarget.tsx +42 -0
- package/src/react/context.ts +10 -0
- package/src/react/hooks.ts +75 -0
- package/src/react/placement.ts +86 -0
- package/src/react-navigation.tsx +80 -0
- package/src/types.ts +96 -0
- package/dist/DapContext.d.ts +0 -2
- package/dist/DapContext.js +0 -5
- package/dist/DapOverlay.d.ts +0 -2
- package/dist/DapOverlay.js +0 -195
- package/dist/DapProvider.d.ts +0 -8
- package/dist/DapProvider.js +0 -227
- package/dist/DapScrollView.d.ts +0 -8
- package/dist/DapScrollView.js +0 -62
- package/dist/DapTarget.d.ts +0 -8
- package/dist/DapTarget.js +0 -137
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -22
- package/dist/types.d.ts +0 -37
- package/dist/types.js +0 -2
- package/dist/useDap.d.ts +0 -1
- package/dist/useDap.js +0 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vishwas Gaur
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# rn-smart-tour
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<b>
|
|
4
|
+
<b>Digital Adoption Platform (DAP) for React Native</b><br>
|
|
5
5
|
Easily add product tours, guided walkthroughs, and onboarding overlays without intrusive code changes.
|
|
6
6
|
</p>
|
|
7
7
|
|
|
@@ -9,34 +9,42 @@
|
|
|
9
9
|
|
|
10
10
|
## ✨ Features
|
|
11
11
|
|
|
12
|
-
- 🎯 **
|
|
13
|
-
-
|
|
14
|
-
-
|
|
12
|
+
- 🎯 **Measured When Shown**: Targets are measured when their step starts, after scrolling into view and once they stop moving, so the highlight matches what's on screen.
|
|
13
|
+
- 🧭 **Navigation Aware**: Screens kept mounted in the background are never highlighted, and steps wait for screen transitions to finish (React Navigation integration included).
|
|
14
|
+
- 🔀 **Tours Across Screens**: A step can navigate to another screen before it is shown.
|
|
15
|
+
- 📜 **Auto-Scroll**: Works with `ScrollView`, `FlatList` and `SectionList`; each target scrolls its own nearest list.
|
|
16
|
+
- ⚡ **No Re-Render Cost**: Mounting and measuring targets re-renders nothing; components subscribe only to the tour state they use.
|
|
15
17
|
- 💾 **Seen State Caching**: Persistent "only-once" logic with pluggable storage (AsyncStorage, MMKV, etc.).
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
+
- 🛟 **Never Gets Stuck**: If a step's target isn't on screen in time, the tour ends (or skips the step) instead of leaving an invisible, active tour.
|
|
19
|
+
- 🔁 **Replay on Demand**: `startTour(id, { force: true })`, `resetTour(id)` and `resetAll()`, from components or from outside React.
|
|
18
20
|
|
|
19
21
|
---
|
|
20
22
|
|
|
21
23
|
## 📦 Installation
|
|
22
24
|
|
|
23
25
|
```sh
|
|
24
|
-
npm install rn-smart-tour
|
|
26
|
+
npm install rn-smart-tour@next # 2.0 beta (this README)
|
|
27
|
+
npm install rn-smart-tour # 1.x (stable)
|
|
25
28
|
```
|
|
26
29
|
|
|
30
|
+
Requires React 18+ and React Native 0.73+. No native code, so no `pod install` or rebuild is needed. React Navigation (6+) is optional.
|
|
31
|
+
|
|
32
|
+
Checked on device on iOS and Android with React Native 0.88 (New Architecture), and on iOS with React Native 0.81 on the old architecture, with React Navigation 7. Unit tests run against React Native 0.73.
|
|
33
|
+
|
|
27
34
|
---
|
|
28
35
|
|
|
29
36
|
## 🚀 Quick Start
|
|
30
37
|
|
|
31
38
|
### 1. Wrap your App
|
|
32
|
-
Wrap your root component in
|
|
39
|
+
Wrap your root component in `TourProvider` and define your tours.
|
|
33
40
|
|
|
34
41
|
```tsx
|
|
35
|
-
import {
|
|
42
|
+
import { TourProvider } from 'rn-smart-tour';
|
|
36
43
|
|
|
37
44
|
const TOURS = {
|
|
38
45
|
'welcome-tour': {
|
|
39
46
|
id: 'welcome-tour',
|
|
47
|
+
autoStart: true,
|
|
40
48
|
steps: [{
|
|
41
49
|
targetId: 'save-btn',
|
|
42
50
|
title: 'Welcome!',
|
|
@@ -47,49 +55,160 @@ const TOURS = {
|
|
|
47
55
|
|
|
48
56
|
export default function App() {
|
|
49
57
|
return (
|
|
50
|
-
<
|
|
58
|
+
<TourProvider tours={TOURS}>
|
|
51
59
|
<MainApp />
|
|
52
|
-
</
|
|
60
|
+
</TourProvider>
|
|
53
61
|
);
|
|
54
62
|
}
|
|
55
63
|
```
|
|
56
64
|
|
|
57
|
-
### 2. Mark your
|
|
58
|
-
Wrap any view or button you want to highlight with `
|
|
65
|
+
### 2. Mark your Targets
|
|
66
|
+
Wrap any view or button you want to highlight with `TourTarget`.
|
|
59
67
|
|
|
60
68
|
```tsx
|
|
61
|
-
import {
|
|
69
|
+
import { TourTarget } from 'rn-smart-tour';
|
|
62
70
|
|
|
63
71
|
const MyButton = () => (
|
|
64
|
-
<
|
|
72
|
+
<TourTarget name="save-btn">
|
|
65
73
|
<Button title="Save" onPress={...} />
|
|
66
|
-
</
|
|
74
|
+
</TourTarget>
|
|
67
75
|
);
|
|
68
76
|
```
|
|
69
77
|
|
|
70
78
|
### 3. Start the Tour
|
|
71
|
-
|
|
79
|
+
A tour with `autoStart: true` shows the first time its first target appears. Start any tour yourself with `useTour`:
|
|
72
80
|
|
|
73
81
|
```tsx
|
|
74
|
-
import {
|
|
82
|
+
import { useTour } from 'rn-smart-tour';
|
|
75
83
|
|
|
76
|
-
const { startTour } =
|
|
84
|
+
const { startTour } = useTour();
|
|
77
85
|
// ...
|
|
78
|
-
|
|
86
|
+
// A tour is shown only once. `force: true` replays it, e.g. from a Help button.
|
|
87
|
+
<Button title="Help" onPress={() => startTour('welcome-tour', { force: true })} />
|
|
79
88
|
```
|
|
80
89
|
|
|
81
|
-
### 4.
|
|
82
|
-
|
|
90
|
+
### 4. Screens (React Navigation)
|
|
91
|
+
Wrap each screen that has targets in `NavigationTourScope`. Its targets then only count while the screen is focused and has finished animating in, so a screen kept mounted in the background is never highlighted.
|
|
83
92
|
|
|
84
93
|
```tsx
|
|
85
|
-
import {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
import { NavigationTourScope } from 'rn-smart-tour/react-navigation';
|
|
95
|
+
|
|
96
|
+
const OrdersScreen = () => (
|
|
97
|
+
<NavigationTourScope>
|
|
98
|
+
{/* screen content with TourTargets */}
|
|
99
|
+
</NavigationTourScope>
|
|
100
|
+
);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Not using React Navigation? `TourScope` does the same with an `active` prop you control: `<TourScope active={isVisible}>`.
|
|
104
|
+
|
|
105
|
+
### 5. Lists (Optional)
|
|
106
|
+
To let tours scroll a target into view, use `TourScrollView` instead of `ScrollView`, or wrap a `FlatList` / `SectionList` in `TourScrollable`:
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { TourScrollable, TourTarget } from 'rn-smart-tour';
|
|
110
|
+
|
|
111
|
+
const listRef = useRef<FlatList>(null);
|
|
112
|
+
|
|
113
|
+
<TourScrollable scrollRef={listRef}>
|
|
114
|
+
<FlatList
|
|
115
|
+
ref={listRef}
|
|
116
|
+
data={items}
|
|
117
|
+
renderItem={({ item }) => (
|
|
118
|
+
<TourTarget name={`item-${item.id}`}>
|
|
119
|
+
<Row item={item} />
|
|
120
|
+
</TourTarget>
|
|
121
|
+
)}
|
|
122
|
+
/>
|
|
123
|
+
</TourScrollable>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A target in a virtualized list can only be scrolled to once its row has rendered.
|
|
127
|
+
|
|
128
|
+
### 6. Tours Across Screens (Optional)
|
|
129
|
+
`beforeEnter` runs before a step looks for its target, e.g. to open the screen it's on. The step then waits for the target to appear on the focused screen.
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import { createNavigationContainerRef } from '@react-navigation/native';
|
|
133
|
+
|
|
134
|
+
export const navigationRef = createNavigationContainerRef();
|
|
135
|
+
|
|
136
|
+
const TOURS = {
|
|
137
|
+
orders: {
|
|
138
|
+
id: 'orders',
|
|
139
|
+
steps: [
|
|
140
|
+
{ targetId: 'orders-tab', title: 'Orders', description: 'All your orders live here.' },
|
|
141
|
+
{
|
|
142
|
+
targetId: 'new-order',
|
|
143
|
+
title: 'New order',
|
|
144
|
+
description: 'Start one from here.',
|
|
145
|
+
beforeEnter: () => navigationRef.navigate('Orders'),
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 7. Remember Seen Tours (Optional)
|
|
153
|
+
Without a `storageAdapter`, "seen" state lasts until the app restarts. Pass any storage with `getItem` / `setItem`:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
157
|
+
|
|
158
|
+
<TourProvider tours={TOURS} storageAdapter={AsyncStorage}>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import { createMMKV } from 'react-native-mmkv'; // v4; on v3: `const mmkv = new MMKV()`
|
|
163
|
+
|
|
164
|
+
const mmkv = createMMKV();
|
|
165
|
+
const mmkvAdapter = {
|
|
166
|
+
getItem: (key: string) => mmkv.getString(key) ?? null,
|
|
167
|
+
setItem: (key: string, value: string) => mmkv.set(key, value),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
<TourProvider tours={TOURS} storageAdapter={mmkvAdapter}>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Storage is read once on mount. Calls to `startTour`, `resetTour` and `resetAll` made before it has loaded are queued and run once it has, so an already-seen tour is never shown by mistake.
|
|
174
|
+
|
|
175
|
+
### 8. Your Own Tooltip Card (Optional)
|
|
176
|
+
Render the card with your design system and theme. It is placed beside the target for you (below by default, flipping above when there's no room), using its measured height.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import type { TourTooltipProps } from 'rn-smart-tour';
|
|
180
|
+
|
|
181
|
+
const TourCard = ({ step, stepIndex, stepCount, isFirstStep, isLastStep, next, prev, skip }: TourTooltipProps) => (
|
|
182
|
+
<Card>
|
|
183
|
+
<Title>{step.title}</Title>
|
|
184
|
+
<Body>{step.description}</Body>
|
|
185
|
+
<Row>
|
|
186
|
+
{!isLastStep && <Button title="Skip" onPress={skip} />}
|
|
187
|
+
{!isFirstStep && <Button title="Back" onPress={prev} />}
|
|
188
|
+
<Button title={isLastStep ? 'Done' : `Next (${stepIndex + 1}/${stepCount})`} onPress={next} />
|
|
189
|
+
</Row>
|
|
190
|
+
</Card>
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
<TourProvider
|
|
194
|
+
tours={TOURS}
|
|
195
|
+
renderTooltip={props => <TourCard {...props} />}
|
|
196
|
+
tooltipWidth={320}
|
|
197
|
+
backdropColor="rgba(0, 0, 0, 0.6)">
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 9. Start Tours from Outside React (Optional)
|
|
201
|
+
For deep links or notification handlers, create a controller and pass it to the provider:
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
import { createTourController, TourProvider } from 'rn-smart-tour';
|
|
205
|
+
|
|
206
|
+
export const tours = createTourController({ tours: TOURS, storageAdapter: mmkvAdapter });
|
|
207
|
+
|
|
208
|
+
<TourProvider controller={tours}>…</TourProvider>
|
|
209
|
+
|
|
210
|
+
// anywhere:
|
|
211
|
+
tours.startTour('new-feature', { force: true });
|
|
93
212
|
```
|
|
94
213
|
|
|
95
214
|
---
|
|
@@ -97,22 +216,35 @@ import { DapScrollView } from 'rn-smart-tour';
|
|
|
97
216
|
## 🧠 Technical Architecture
|
|
98
217
|
|
|
99
218
|
<details>
|
|
100
|
-
<summary><b>
|
|
219
|
+
<summary><b>How Measurement Works (Click to expand)</b></summary>
|
|
101
220
|
|
|
102
|
-
|
|
221
|
+
Targets only register a ref. When a step starts:
|
|
103
222
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
223
|
+
1. `beforeEnter` runs, if the step has one, and is awaited.
|
|
224
|
+
2. The engine waits for the target to be mounted inside an active scope.
|
|
225
|
+
3. If the target is in a `TourScrollable` and not fully visible, the list scrolls it to the middle.
|
|
226
|
+
4. The target is measured every frame until its position holds steady for 3 frames, then the step is shown.
|
|
107
227
|
|
|
108
|
-
|
|
228
|
+
While a step is shown, its target is measured again when its layout changes, the window resizes, the keyboard opens or closes, or the app returns to the foreground. Positions that change by **1pt** or less are ignored.
|
|
109
229
|
|
|
110
230
|
</details>
|
|
111
231
|
|
|
112
232
|
<details>
|
|
113
233
|
<summary><b>Auto-Start & Debounce Settings</b></summary>
|
|
114
234
|
|
|
115
|
-
When `autoStart: true` is enabled, the
|
|
235
|
+
When `autoStart: true` is enabled, the tour starts **300ms** after its first target is registered in an active scope, so the rest of the screen can mount first.
|
|
236
|
+
|
|
237
|
+
A tour that is stopped (finished, skipped, or ended because a target was missing) is not auto-started again in the same app session. `startTour` still works, and `resetTour` makes it eligible again.
|
|
238
|
+
|
|
239
|
+
</details>
|
|
240
|
+
|
|
241
|
+
<details>
|
|
242
|
+
<summary><b>Tour Lifecycle Rules</b></summary>
|
|
243
|
+
|
|
244
|
+
- **Skip**, **Finish** and the **Android back button** end the tour and mark it as seen.
|
|
245
|
+
- If a step's target is not on screen within `missingTargetTimeoutMs` (default **3000ms**, or the step's `targetTimeoutMs`), the tour ends **without** being marked as seen, or moves to the next step with `onMissingTarget: 'skip'`. A warning is logged in development.
|
|
246
|
+
- If the target of the step being shown disappears (unmounts, or its screen loses focus), the step is hidden until it comes back, within the same timeout.
|
|
247
|
+
- While moving to the next step, the current one stays on screen until the next target is measured, and extra taps on **Next** are ignored.
|
|
116
248
|
|
|
117
249
|
</details>
|
|
118
250
|
|
|
@@ -120,43 +252,80 @@ When `autoStart: true` is enabled, the overlay waits **300ms** after registratio
|
|
|
120
252
|
|
|
121
253
|
## 🛠 API Reference
|
|
122
254
|
|
|
255
|
+
### TourProvider
|
|
256
|
+
| Property | Type | Default | Description |
|
|
257
|
+
|:---|:---|:---|:---|
|
|
258
|
+
| `tours` | `Record<string, Tour>` | — | All tours, keyed by id. |
|
|
259
|
+
| `storageAdapter` | `StorageAdapter` | — | Persists seen tours (AsyncStorage, MMKV, …). Read once on mount. |
|
|
260
|
+
| `missingTargetTimeoutMs` | `number` | `3000` | How long a step waits for its target. |
|
|
261
|
+
| `controller` | `TourController` | — | From `createTourController`, instead of `tours` / `storageAdapter`. |
|
|
262
|
+
| `renderTooltip` | `(props: TourTooltipProps) => ReactNode` | built-in card | Draws the tooltip card. Receives the step, its index and count, and `next` / `prev` / `skip`. |
|
|
263
|
+
| `tooltipWidth` | `number` | `280` | Card width (capped to the screen). |
|
|
264
|
+
| `backdropColor` | `string` | `'rgba(0, 0, 0, 0.6)'` | Color of the dimmed area around the target. |
|
|
265
|
+
|
|
123
266
|
### Tour Configuration
|
|
124
267
|
| Property | Type | Description |
|
|
125
268
|
|:---|:---|:---|
|
|
126
269
|
| `id` | `string` | Unique identifier for caching. |
|
|
127
|
-
| `autoStart` | `boolean` |
|
|
270
|
+
| `autoStart` | `boolean` | Start the first time the first step's target appears. |
|
|
128
271
|
| `steps` | `TourStep[]` | Sequence of highlight steps. |
|
|
129
272
|
|
|
130
|
-
### DapScrollView
|
|
131
|
-
A direct drop-in replacement for the React Native `ScrollView`. Supports all standard props.
|
|
132
|
-
| Property | Type | Description |
|
|
133
|
-
|:---|:---|:---|
|
|
134
|
-
| `children` | `React.Node` | Components to scroll. |
|
|
135
|
-
| `...props` | `ScrollViewProps` | Standard props are forwarded to the native ScrollView. |
|
|
136
|
-
|
|
137
|
-
### DapTarget
|
|
138
|
-
| Property | Type | Description |
|
|
139
|
-
|:---|:---|:---|
|
|
140
|
-
| `name` | `string` | Unique identifier that matches a `targetId` in a tour step. |
|
|
141
|
-
| `children` | `ReactElement` | The UI element to wrap and highlight. |
|
|
142
|
-
| `...props` | `ViewProps` | All standard React Native `View` props are forwarded. |
|
|
143
|
-
|
|
144
273
|
### TourStep
|
|
145
274
|
| Property | Type | Default | Description |
|
|
146
275
|
|:---|:---|:---|:---|
|
|
147
|
-
| `targetId` | `string` | — | Matches the `name` prop
|
|
276
|
+
| `targetId` | `string` | — | Matches the `name` prop of a `<TourTarget>`. |
|
|
148
277
|
| `title` | `string` | — | Tooltip header. |
|
|
149
278
|
| `description` | `string` | — | Tooltip body. |
|
|
150
279
|
| `position` | `string` | `'bottom'` | `top`, `bottom`, `left`, `right`. |
|
|
280
|
+
| `beforeEnter` | `() => void \| Promise<void>` | — | Runs (and is awaited) before the step looks for its target. |
|
|
281
|
+
| `onMissingTarget` | `'end' \| 'skip'` | `'end'` | What happens if the target isn't found in time. |
|
|
282
|
+
| `targetTimeoutMs` | `number` | provider's | Per-step override of `missingTargetTimeoutMs`. |
|
|
283
|
+
|
|
284
|
+
### TourTarget
|
|
285
|
+
| Property | Type | Description |
|
|
286
|
+
|:---|:---|:---|
|
|
287
|
+
| `name` | `string` | Matches a `targetId` in a tour step. |
|
|
288
|
+
| `children` | `ReactNode` | The UI element to wrap and highlight. |
|
|
289
|
+
| `...props` | `ViewProps` | All standard React Native `View` props are forwarded. |
|
|
290
|
+
|
|
291
|
+
### TourScope / NavigationTourScope
|
|
292
|
+
| Component | Props | Description |
|
|
293
|
+
|:---|:---|:---|
|
|
294
|
+
| `TourScope` | `active?: boolean` (default `true`) | Targets inside only count while `active` (and every parent scope is active). |
|
|
295
|
+
| `NavigationTourScope` | — | From `rn-smart-tour/react-navigation`. Active while the screen is focused and not animating. |
|
|
296
|
+
|
|
297
|
+
### TourScrollable / TourScrollView
|
|
298
|
+
| Component | Props | Description |
|
|
299
|
+
|:---|:---|:---|
|
|
300
|
+
| `TourScrollable` | `scrollRef`, `horizontal?` | Lets tours scroll targets inside the referenced `ScrollView` / `FlatList` / `SectionList`. |
|
|
301
|
+
| `TourScrollView` | `ScrollViewProps` | A `ScrollView` already wrapped in `TourScrollable`. A `ref` is forwarded. |
|
|
151
302
|
|
|
152
|
-
### `
|
|
153
|
-
|
|
|
303
|
+
### `useTour()` Hook
|
|
304
|
+
| Member | Description |
|
|
154
305
|
|:---|:---|
|
|
155
|
-
| `startTour(id)` | Start a tour by ID. |
|
|
306
|
+
| `startTour(id, options?)` | Start a tour by ID. Does nothing if it was already seen, unless `{ force: true }`. |
|
|
156
307
|
| `stopTour(markAsSeen?)`| End tour. Pass `false` to keep it unread. |
|
|
157
308
|
| `nextStep()` / `prevStep()` | Manual step navigation. |
|
|
309
|
+
| `resetTour(id)` | Mark a tour as unseen so it can show (and auto-start) again. |
|
|
310
|
+
| `resetAll()` | Mark every tour as unseen. |
|
|
311
|
+
| `status` | `'idle'`, `'waiting'` (looking for the step's target) or `'active'`. |
|
|
158
312
|
| `activeTour` | Current active tour object. |
|
|
159
313
|
| `currentStepIndex` | Current step number (0-indexed). |
|
|
314
|
+
| `seenTours` | `Record<string, boolean>` of tours already seen. |
|
|
315
|
+
|
|
316
|
+
`useTourState(selector)` subscribes to any slice of the tour state and re-renders only when it changes.
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## ⬆️ Upgrading from 1.x
|
|
321
|
+
|
|
322
|
+
The 1.x names still work and are deprecated: `DapProvider` → `TourProvider`, `DapTarget` → `TourTarget`, `DapScrollView` → `TourScrollView`, `useDap` → `useTour`. Seen tours stored by 1.x are kept.
|
|
323
|
+
|
|
324
|
+
Behaviour changes:
|
|
325
|
+
- React ≥ 18 and React Native ≥ 0.73 are required.
|
|
326
|
+
- A step appears a few frames after it starts (once its target has stopped moving), not immediately.
|
|
327
|
+
- `useDap().targets` only contains the measurement of the step being shown, and `requestScroll` does nothing; scrolling is automatic.
|
|
328
|
+
- Wrap screens in `NavigationTourScope` (or `TourScope`) to stop targets on background screens from being used.
|
|
160
329
|
|
|
161
330
|
---
|
|
162
331
|
|
|
@@ -164,8 +333,22 @@ A direct drop-in replacement for the React Native `ScrollView`. Supports all sta
|
|
|
164
333
|
|
|
165
334
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
166
335
|
|
|
336
|
+
```sh
|
|
337
|
+
npm install
|
|
338
|
+
npm run typecheck && npm run lint && npm test # what CI runs
|
|
339
|
+
npm run build # outputs lib/ (CommonJS, ES modules, types)
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
The `example/` app (React Native 0.88, React Navigation) loads the library straight from `src/`, so changes show up without a build:
|
|
343
|
+
|
|
344
|
+
```sh
|
|
345
|
+
cd example && npm install
|
|
346
|
+
cd ios && pod install && cd ..
|
|
347
|
+
npm run ios # or: npm run android
|
|
348
|
+
```
|
|
349
|
+
|
|
167
350
|
---
|
|
168
351
|
|
|
169
352
|
<p align="center">
|
|
170
353
|
<b>rn-smart-tour</b> • Built with ❤️ for the React Native community.
|
|
171
|
-
</p>
|
|
354
|
+
</p>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DapTarget = exports.DapScrollView = exports.DapProvider = void 0;
|
|
7
|
+
exports.useDap = useDap;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _context = require("./react/context.js");
|
|
10
|
+
var _hooks = require("./react/hooks.js");
|
|
11
|
+
var _TourProvider = require("./react/TourProvider.js");
|
|
12
|
+
var _TourScrollable = require("./react/TourScrollable.js");
|
|
13
|
+
var _TourTarget = require("./react/TourTarget.js");
|
|
14
|
+
/**
|
|
15
|
+
* The 1.x API (`Dap*` names and `useDap`), kept so existing apps keep working.
|
|
16
|
+
* New code should use `TourProvider`, `TourTarget`, `TourScrollView` and `useTour`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** @deprecated Use `TourProvider`. */
|
|
20
|
+
const DapProvider = exports.DapProvider = _TourProvider.TourProvider;
|
|
21
|
+
/** @deprecated Use `TourProviderProps`. */
|
|
22
|
+
|
|
23
|
+
/** @deprecated Use `TourTarget`. */
|
|
24
|
+
const DapTarget = exports.DapTarget = _TourTarget.TourTarget;
|
|
25
|
+
/** @deprecated Use `TourScrollView`. */
|
|
26
|
+
const DapScrollView = exports.DapScrollView = _TourScrollable.TourScrollView;
|
|
27
|
+
/**
|
|
28
|
+
* 1.x `registerTarget` / `unregisterTarget`, created once per engine: callers
|
|
29
|
+
* register from effects, so the functions must keep the same identity across renders.
|
|
30
|
+
*/
|
|
31
|
+
const legacyRegistries = new WeakMap();
|
|
32
|
+
function getLegacyRegistry(engine) {
|
|
33
|
+
let registry = legacyRegistries.get(engine);
|
|
34
|
+
if (!registry) {
|
|
35
|
+
const registrations = new Map();
|
|
36
|
+
const unregisterTarget = id => {
|
|
37
|
+
registrations.get(id)?.();
|
|
38
|
+
registrations.delete(id);
|
|
39
|
+
};
|
|
40
|
+
const registerTarget = (id, measurement, ref) => {
|
|
41
|
+
unregisterTarget(id);
|
|
42
|
+
// Without a ref, report the given measurement whenever the engine measures.
|
|
43
|
+
const measurable = ref ?? {
|
|
44
|
+
measureInWindow: cb => cb(measurement.x, measurement.y, measurement.width, measurement.height)
|
|
45
|
+
};
|
|
46
|
+
registrations.set(id, engine.registerTarget(id, {
|
|
47
|
+
ref: {
|
|
48
|
+
current: measurable
|
|
49
|
+
},
|
|
50
|
+
scope: null,
|
|
51
|
+
scrollable: null
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
registry = {
|
|
55
|
+
registerTarget,
|
|
56
|
+
unregisterTarget
|
|
57
|
+
};
|
|
58
|
+
legacyRegistries.set(engine, registry);
|
|
59
|
+
}
|
|
60
|
+
return registry;
|
|
61
|
+
}
|
|
62
|
+
const noop = () => {};
|
|
63
|
+
|
|
64
|
+
/** @deprecated Use `useTour`. */
|
|
65
|
+
function useDap() {
|
|
66
|
+
const engine = (0, _react.useContext)(_context.TourEngineContext);
|
|
67
|
+
if (!engine) {
|
|
68
|
+
throw new Error('useDap must be used within a DapProvider');
|
|
69
|
+
}
|
|
70
|
+
const api = (0, _hooks.useTour)();
|
|
71
|
+
// 1.x consumers re-rendered on every measurement and could read `targets`.
|
|
72
|
+
const presented = (0, _hooks.useTourState)(state => state.presented);
|
|
73
|
+
return (0, _react.useMemo)(() => {
|
|
74
|
+
const presentedStep = presented && engine.getTour(presented.tourId)?.steps[presented.stepIndex];
|
|
75
|
+
return {
|
|
76
|
+
...api,
|
|
77
|
+
...getLegacyRegistry(engine),
|
|
78
|
+
targets: presented && presentedStep ? {
|
|
79
|
+
[presentedStep.targetId]: presented.rect
|
|
80
|
+
} : {},
|
|
81
|
+
requestScroll: noop,
|
|
82
|
+
_registerScrollRef: noop,
|
|
83
|
+
_unregisterScrollRef: noop
|
|
84
|
+
};
|
|
85
|
+
}, [engine, api, presented]);
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_context","_hooks","_TourProvider","_TourScrollable","_TourTarget","DapProvider","exports","TourProvider","DapTarget","TourTarget","DapScrollView","TourScrollView","legacyRegistries","WeakMap","getLegacyRegistry","engine","registry","get","registrations","Map","unregisterTarget","id","delete","registerTarget","measurement","ref","measurable","measureInWindow","cb","x","y","width","height","set","current","scope","scrollable","noop","useDap","useContext","TourEngineContext","Error","api","useTour","presented","useTourState","state","useMemo","presentedStep","getTour","tourId","steps","stepIndex","targets","targetId","rect","requestScroll","_registerScrollRef","_unregisterScrollRef"],"sourceRoot":"../../src","sources":["compat.ts"],"mappings":"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","ignoreList":[]}
|