rn-smart-tour 1.1.0 → 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.
Files changed (197) hide show
  1. package/README.md +186 -68
  2. package/lib/commonjs/compat.js +87 -0
  3. package/lib/commonjs/compat.js.map +1 -0
  4. package/lib/commonjs/core/TourEngine.js +450 -0
  5. package/lib/commonjs/core/TourEngine.js.map +1 -0
  6. package/lib/commonjs/core/controller.js +34 -0
  7. package/lib/commonjs/core/controller.js.map +1 -0
  8. package/lib/commonjs/core/measure.js +130 -0
  9. package/lib/commonjs/core/measure.js.map +1 -0
  10. package/lib/commonjs/core/store.js +39 -0
  11. package/lib/commonjs/core/store.js.map +1 -0
  12. package/lib/commonjs/index.js +81 -44
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/react/TourOverlay.js +290 -0
  15. package/lib/commonjs/react/TourOverlay.js.map +1 -0
  16. package/lib/commonjs/react/TourProvider.js +62 -0
  17. package/lib/commonjs/react/TourProvider.js.map +1 -0
  18. package/lib/commonjs/react/TourScope.js +39 -0
  19. package/lib/commonjs/react/TourScope.js.map +1 -0
  20. package/lib/commonjs/react/TourScrollable.js +61 -0
  21. package/lib/commonjs/react/TourScrollable.js.map +1 -0
  22. package/lib/commonjs/react/TourTarget.js +51 -0
  23. package/lib/commonjs/react/TourTarget.js.map +1 -0
  24. package/lib/commonjs/react/context.js +15 -0
  25. package/lib/commonjs/react/context.js.map +1 -0
  26. package/lib/commonjs/react/hooks.js +81 -0
  27. package/lib/commonjs/react/hooks.js.map +1 -0
  28. package/lib/commonjs/react/placement.js +61 -0
  29. package/lib/commonjs/react/placement.js.map +1 -0
  30. package/lib/commonjs/react-navigation.js +80 -0
  31. package/lib/commonjs/react-navigation.js.map +1 -0
  32. package/lib/module/compat.js +81 -0
  33. package/lib/module/compat.js.map +1 -0
  34. package/lib/module/core/TourEngine.js +446 -0
  35. package/lib/module/core/TourEngine.js.map +1 -0
  36. package/lib/module/core/controller.js +29 -0
  37. package/lib/module/core/controller.js.map +1 -0
  38. package/lib/module/core/measure.js +118 -0
  39. package/lib/module/core/measure.js.map +1 -0
  40. package/lib/module/core/store.js +34 -0
  41. package/lib/module/core/store.js.map +1 -0
  42. package/lib/module/index.js +8 -5
  43. package/lib/module/index.js.map +1 -1
  44. package/lib/module/react/TourOverlay.js +282 -0
  45. package/lib/module/react/TourOverlay.js.map +1 -0
  46. package/lib/module/react/TourProvider.js +55 -0
  47. package/lib/module/react/TourProvider.js.map +1 -0
  48. package/lib/module/react/TourScope.js +32 -0
  49. package/lib/module/react/TourScope.js.map +1 -0
  50. package/lib/module/react/TourScrollable.js +54 -0
  51. package/lib/module/react/TourScrollable.js.map +1 -0
  52. package/lib/module/react/TourTarget.js +44 -0
  53. package/lib/module/react/TourTarget.js.map +1 -0
  54. package/lib/module/react/context.js +11 -0
  55. package/lib/module/react/context.js.map +1 -0
  56. package/lib/module/react/hooks.js +73 -0
  57. package/lib/module/react/hooks.js.map +1 -0
  58. package/lib/module/react/placement.js +57 -0
  59. package/lib/module/react/placement.js.map +1 -0
  60. package/lib/module/react-navigation.js +74 -0
  61. package/lib/module/react-navigation.js.map +1 -0
  62. package/lib/typescript/commonjs/src/compat.d.ts +13 -0
  63. package/lib/typescript/commonjs/src/compat.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/src/core/TourEngine.d.ts +113 -0
  65. package/lib/typescript/commonjs/src/core/TourEngine.d.ts.map +1 -0
  66. package/lib/typescript/commonjs/src/core/controller.d.ts +33 -0
  67. package/lib/typescript/commonjs/src/core/controller.d.ts.map +1 -0
  68. package/lib/typescript/commonjs/src/core/measure.d.ts +26 -0
  69. package/lib/typescript/commonjs/src/core/measure.d.ts.map +1 -0
  70. package/lib/typescript/commonjs/src/core/store.d.ts +9 -0
  71. package/lib/typescript/commonjs/src/core/store.d.ts.map +1 -0
  72. package/lib/typescript/commonjs/src/index.d.ts +15 -5
  73. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/react/TourOverlay.d.ts +17 -0
  75. package/lib/typescript/commonjs/src/react/TourOverlay.d.ts.map +1 -0
  76. package/lib/typescript/commonjs/src/react/TourProvider.d.ts +27 -0
  77. package/lib/typescript/commonjs/src/react/TourProvider.d.ts.map +1 -0
  78. package/lib/typescript/commonjs/src/react/TourScope.d.ts +17 -0
  79. package/lib/typescript/commonjs/src/react/TourScope.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/src/react/TourScrollable.d.ts +25 -0
  81. package/lib/typescript/commonjs/src/react/TourScrollable.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/src/react/TourTarget.d.ts +13 -0
  83. package/lib/typescript/commonjs/src/react/TourTarget.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/src/react/context.d.ts +7 -0
  85. package/lib/typescript/commonjs/src/react/context.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/react/hooks.d.ts +12 -0
  87. package/lib/typescript/commonjs/src/react/hooks.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/react/placement.d.ts +19 -0
  89. package/lib/typescript/commonjs/src/react/placement.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/react-navigation.d.ts +15 -0
  91. package/lib/typescript/commonjs/src/react-navigation.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/types.d.ts +49 -8
  93. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  94. package/lib/typescript/module/src/compat.d.ts +13 -0
  95. package/lib/typescript/module/src/compat.d.ts.map +1 -0
  96. package/lib/typescript/module/src/core/TourEngine.d.ts +113 -0
  97. package/lib/typescript/module/src/core/TourEngine.d.ts.map +1 -0
  98. package/lib/typescript/module/src/core/controller.d.ts +33 -0
  99. package/lib/typescript/module/src/core/controller.d.ts.map +1 -0
  100. package/lib/typescript/module/src/core/measure.d.ts +26 -0
  101. package/lib/typescript/module/src/core/measure.d.ts.map +1 -0
  102. package/lib/typescript/module/src/core/store.d.ts +9 -0
  103. package/lib/typescript/module/src/core/store.d.ts.map +1 -0
  104. package/lib/typescript/module/src/index.d.ts +15 -5
  105. package/lib/typescript/module/src/index.d.ts.map +1 -1
  106. package/lib/typescript/module/src/react/TourOverlay.d.ts +17 -0
  107. package/lib/typescript/module/src/react/TourOverlay.d.ts.map +1 -0
  108. package/lib/typescript/module/src/react/TourProvider.d.ts +27 -0
  109. package/lib/typescript/module/src/react/TourProvider.d.ts.map +1 -0
  110. package/lib/typescript/module/src/react/TourScope.d.ts +17 -0
  111. package/lib/typescript/module/src/react/TourScope.d.ts.map +1 -0
  112. package/lib/typescript/module/src/react/TourScrollable.d.ts +25 -0
  113. package/lib/typescript/module/src/react/TourScrollable.d.ts.map +1 -0
  114. package/lib/typescript/module/src/react/TourTarget.d.ts +13 -0
  115. package/lib/typescript/module/src/react/TourTarget.d.ts.map +1 -0
  116. package/lib/typescript/module/src/react/context.d.ts +7 -0
  117. package/lib/typescript/module/src/react/context.d.ts.map +1 -0
  118. package/lib/typescript/module/src/react/hooks.d.ts +12 -0
  119. package/lib/typescript/module/src/react/hooks.d.ts.map +1 -0
  120. package/lib/typescript/module/src/react/placement.d.ts +19 -0
  121. package/lib/typescript/module/src/react/placement.d.ts.map +1 -0
  122. package/lib/typescript/module/src/react-navigation.d.ts +15 -0
  123. package/lib/typescript/module/src/react-navigation.d.ts.map +1 -0
  124. package/lib/typescript/module/src/types.d.ts +49 -8
  125. package/lib/typescript/module/src/types.d.ts.map +1 -1
  126. package/package.json +25 -6
  127. package/react-navigation/package.json +6 -0
  128. package/src/compat.ts +84 -0
  129. package/src/core/TourEngine.ts +483 -0
  130. package/src/core/controller.ts +43 -0
  131. package/src/core/measure.ts +129 -0
  132. package/src/core/store.ts +39 -0
  133. package/src/index.ts +15 -5
  134. package/src/react/TourOverlay.tsx +260 -0
  135. package/src/react/TourProvider.tsx +82 -0
  136. package/src/react/TourScope.tsx +33 -0
  137. package/src/react/TourScrollable.tsx +58 -0
  138. package/src/react/TourTarget.tsx +42 -0
  139. package/src/react/context.ts +10 -0
  140. package/src/react/hooks.ts +75 -0
  141. package/src/react/placement.ts +86 -0
  142. package/src/react-navigation.tsx +80 -0
  143. package/src/types.ts +52 -8
  144. package/lib/commonjs/DapContext.js +0 -9
  145. package/lib/commonjs/DapContext.js.map +0 -1
  146. package/lib/commonjs/DapOverlay.js +0 -223
  147. package/lib/commonjs/DapOverlay.js.map +0 -1
  148. package/lib/commonjs/DapProvider.js +0 -350
  149. package/lib/commonjs/DapProvider.js.map +0 -1
  150. package/lib/commonjs/DapScrollView.js +0 -44
  151. package/lib/commonjs/DapScrollView.js.map +0 -1
  152. package/lib/commonjs/DapTarget.js +0 -116
  153. package/lib/commonjs/DapTarget.js.map +0 -1
  154. package/lib/commonjs/useDap.js +0 -17
  155. package/lib/commonjs/useDap.js.map +0 -1
  156. package/lib/module/DapContext.js +0 -5
  157. package/lib/module/DapContext.js.map +0 -1
  158. package/lib/module/DapOverlay.js +0 -220
  159. package/lib/module/DapOverlay.js.map +0 -1
  160. package/lib/module/DapProvider.js +0 -343
  161. package/lib/module/DapProvider.js.map +0 -1
  162. package/lib/module/DapScrollView.js +0 -41
  163. package/lib/module/DapScrollView.js.map +0 -1
  164. package/lib/module/DapTarget.js +0 -109
  165. package/lib/module/DapTarget.js.map +0 -1
  166. package/lib/module/useDap.js +0 -12
  167. package/lib/module/useDap.js.map +0 -1
  168. package/lib/typescript/commonjs/src/DapContext.d.ts +0 -3
  169. package/lib/typescript/commonjs/src/DapContext.d.ts.map +0 -1
  170. package/lib/typescript/commonjs/src/DapOverlay.d.ts +0 -2
  171. package/lib/typescript/commonjs/src/DapOverlay.d.ts.map +0 -1
  172. package/lib/typescript/commonjs/src/DapProvider.d.ts +0 -15
  173. package/lib/typescript/commonjs/src/DapProvider.d.ts.map +0 -1
  174. package/lib/typescript/commonjs/src/DapScrollView.d.ts +0 -9
  175. package/lib/typescript/commonjs/src/DapScrollView.d.ts.map +0 -1
  176. package/lib/typescript/commonjs/src/DapTarget.d.ts +0 -10
  177. package/lib/typescript/commonjs/src/DapTarget.d.ts.map +0 -1
  178. package/lib/typescript/commonjs/src/useDap.d.ts +0 -2
  179. package/lib/typescript/commonjs/src/useDap.d.ts.map +0 -1
  180. package/lib/typescript/module/src/DapContext.d.ts +0 -3
  181. package/lib/typescript/module/src/DapContext.d.ts.map +0 -1
  182. package/lib/typescript/module/src/DapOverlay.d.ts +0 -2
  183. package/lib/typescript/module/src/DapOverlay.d.ts.map +0 -1
  184. package/lib/typescript/module/src/DapProvider.d.ts +0 -15
  185. package/lib/typescript/module/src/DapProvider.d.ts.map +0 -1
  186. package/lib/typescript/module/src/DapScrollView.d.ts +0 -9
  187. package/lib/typescript/module/src/DapScrollView.d.ts.map +0 -1
  188. package/lib/typescript/module/src/DapTarget.d.ts +0 -10
  189. package/lib/typescript/module/src/DapTarget.d.ts.map +0 -1
  190. package/lib/typescript/module/src/useDap.d.ts +0 -2
  191. package/lib/typescript/module/src/useDap.d.ts.map +0 -1
  192. package/src/DapContext.ts +0 -4
  193. package/src/DapOverlay.tsx +0 -190
  194. package/src/DapProvider.tsx +0 -417
  195. package/src/DapScrollView.tsx +0 -43
  196. package/src/DapTarget.tsx +0 -124
  197. package/src/useDap.ts +0 -10
package/README.md CHANGED
@@ -9,40 +9,42 @@
9
9
 
10
10
  ## ✨ Features
11
11
 
12
- - 🎯 **Multi-Pass Measurement**: Native `measureInWindow` API with self-correcting strategy for animation resilience.
13
- - 📱 **Rotation & Resize Aware**: Targets re-measure automatically on orientation change or split-screen.
14
- - ⚡ **Auto-Start Engine**: Trigger tours instantly on mount with a smart debounce for layout stability.
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
- - 🎨 **Smart Overlays**: Dynamic cutouts with Back/Next/Skip navigation and step indicators.
17
- - 📜 **Auto-Scroll Support**: Bring tour targets into view with `DapScrollView`; the highlight is re-measured after scrolling.
18
- - 🛟 **Never Gets Stuck**: If a step's target isn't on screen, the tour ends cleanly instead of leaving an invisible, active tour.
19
- - 🔁 **Replay on Demand**: `startTour(id, { force: true })`, `resetTour(id)` and `resetAll()` for Help buttons and settings screens.
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.
20
20
 
21
21
  ---
22
22
 
23
23
  ## 📦 Installation
24
24
 
25
25
  ```sh
26
- 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)
27
28
  ```
28
29
 
29
- Requires React 17+ and React Native 0.65+. No native code, so no `pod install` or rebuild is needed.
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.
30
31
 
31
- Unit-tested against React Native 0.73 (React 18), and checked in the example app on React Native 0.88 (React 19, New Architecture) on iOS.
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.
32
33
 
33
34
  ---
34
35
 
35
36
  ## 🚀 Quick Start
36
37
 
37
38
  ### 1. Wrap your App
38
- Wrap your root component in the `DapProvider` and define your tours.
39
+ Wrap your root component in `TourProvider` and define your tours.
39
40
 
40
41
  ```tsx
41
- import { DapProvider } from 'rn-smart-tour';
42
+ import { TourProvider } from 'rn-smart-tour';
42
43
 
43
44
  const TOURS = {
44
45
  'welcome-tour': {
45
46
  id: 'welcome-tour',
47
+ autoStart: true,
46
48
  steps: [{
47
49
  targetId: 'save-btn',
48
50
  title: 'Welcome!',
@@ -53,96 +55,184 @@ const TOURS = {
53
55
 
54
56
  export default function App() {
55
57
  return (
56
- <DapProvider tours={TOURS}>
58
+ <TourProvider tours={TOURS}>
57
59
  <MainApp />
58
- </DapProvider>
60
+ </TourProvider>
59
61
  );
60
62
  }
61
63
  ```
62
64
 
63
- ### 2. Mark your Target
64
- Wrap any view or button you want to highlight with `DapTarget`.
65
+ ### 2. Mark your Targets
66
+ Wrap any view or button you want to highlight with `TourTarget`.
65
67
 
66
68
  ```tsx
67
- import { DapTarget } from 'rn-smart-tour';
69
+ import { TourTarget } from 'rn-smart-tour';
68
70
 
69
71
  const MyButton = () => (
70
- <DapTarget name="save-btn">
72
+ <TourTarget name="save-btn">
71
73
  <Button title="Save" onPress={...} />
72
- </DapTarget>
74
+ </TourTarget>
73
75
  );
74
76
  ```
75
77
 
76
78
  ### 3. Start the Tour
77
- Set `autoStart: true` on a tour to show it the first time its first target appears, or start it yourself with the `useDap` hook.
79
+ A tour with `autoStart: true` shows the first time its first target appears. Start any tour yourself with `useTour`:
78
80
 
79
81
  ```tsx
80
- import { useDap } from 'rn-smart-tour';
82
+ import { useTour } from 'rn-smart-tour';
81
83
 
82
- const { startTour } = useDap();
84
+ const { startTour } = useTour();
83
85
  // ...
84
86
  // A tour is shown only once. `force: true` replays it, e.g. from a Help button.
85
87
  <Button title="Help" onPress={() => startTour('welcome-tour', { force: true })} />
86
88
  ```
87
89
 
88
- ### 4. Enable Auto-Scroll (Optional)
89
- If your targets are hidden inside a long list, swap your standard `ScrollView` for `DapScrollView`. The tour will automatically scroll to bring each target into the user's view.
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.
90
92
 
91
93
  ```tsx
92
- import { DapScrollView } from 'rn-smart-tour';
93
-
94
- // ... inside your screen
95
- <DapScrollView>
96
- <DapTarget name="bottom-btn">
97
- <Button title="Secret Button" ... />
98
- </DapTarget>
99
- </DapScrollView>
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
+ };
100
150
  ```
101
151
 
102
- ### 5. Remember Seen Tours (Optional)
152
+ ### 7. Remember Seen Tours (Optional)
103
153
  Without a `storageAdapter`, "seen" state lasts until the app restarts. Pass any storage with `getItem` / `setItem`:
104
154
 
105
155
  ```tsx
106
156
  import AsyncStorage from '@react-native-async-storage/async-storage';
107
157
 
108
- <DapProvider tours={TOURS} storageAdapter={AsyncStorage}>
158
+ <TourProvider tours={TOURS} storageAdapter={AsyncStorage}>
109
159
  ```
110
160
 
111
161
  ```tsx
112
- import { MMKV } from 'react-native-mmkv';
162
+ import { createMMKV } from 'react-native-mmkv'; // v4; on v3: `const mmkv = new MMKV()`
113
163
 
114
- const mmkv = new MMKV();
164
+ const mmkv = createMMKV();
115
165
  const mmkvAdapter = {
116
166
  getItem: (key: string) => mmkv.getString(key) ?? null,
117
167
  setItem: (key: string, value: string) => mmkv.set(key, value),
118
168
  };
119
169
 
120
- <DapProvider tours={TOURS} storageAdapter={mmkvAdapter}>
170
+ <TourProvider tours={TOURS} storageAdapter={mmkvAdapter}>
121
171
  ```
122
172
 
123
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.
124
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 });
212
+ ```
213
+
125
214
  ---
126
215
 
127
216
  ## 🧠 Technical Architecture
128
217
 
129
218
  <details>
130
- <summary><b>View How Measurements Work (Click to expand)</b></summary>
219
+ <summary><b>How Measurement Works (Click to expand)</b></summary>
131
220
 
132
- To guarantee accuracy during navigation animations, `rn-smart-tour` uses a **multi-pass strategy**:
221
+ Targets only register a ref. When a step starts:
133
222
 
134
- - **Pass 1 (100ms)**: Fast first estimate.
135
- - **Pass 2 (500ms)**: Corrects after most screen transitions finish.
136
- - **Pass 3 (1000ms)**: Final safety net for slow async layout shifts.
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.
137
227
 
138
- Measurements only trigger a re-render if the position changes by more than **1pt (threshold)**.
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.
139
229
 
140
230
  </details>
141
231
 
142
232
  <details>
143
233
  <summary><b>Auto-Start & Debounce Settings</b></summary>
144
234
 
145
- When `autoStart: true` is enabled, the overlay waits **300ms** after registration. This allows the multi-pass system to settle on the final coordinates before the hole is cut into the backdrop.
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.
146
236
 
147
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.
148
238
 
@@ -152,8 +242,9 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
152
242
  <summary><b>Tour Lifecycle Rules</b></summary>
153
243
 
154
244
  - **Skip**, **Finish** and the **Android back button** end the tour and mark it as seen.
155
- - If a step's target is not on screen within `missingTargetTimeoutMs` (default **3000ms**), the tour ends **without** being marked as seen, and a warning is logged in development.
156
- - When a step becomes active, its target is scrolled into view (inside a `DapScrollView`) and measured again, so the highlight matches where it is now.
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.
157
248
 
158
249
  </details>
159
250
 
@@ -161,54 +252,81 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
161
252
 
162
253
  ## 🛠 API Reference
163
254
 
164
- ### DapProvider
255
+ ### TourProvider
165
256
  | Property | Type | Default | Description |
166
257
  |:---|:---|:---|:---|
167
258
  | `tours` | `Record<string, Tour>` | — | All tours, keyed by id. |
168
259
  | `storageAdapter` | `StorageAdapter` | — | Persists seen tours (AsyncStorage, MMKV, …). Read once on mount. |
169
- | `missingTargetTimeoutMs` | `number` | `3000` | How long a step waits for its target before the tour ends. |
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. |
170
265
 
171
266
  ### Tour Configuration
172
267
  | Property | Type | Description |
173
268
  |:---|:---|:---|
174
269
  | `id` | `string` | Unique identifier for caching. |
175
- | `autoStart` | `boolean` | Trigger as soon as the first target mounts. |
270
+ | `autoStart` | `boolean` | Start the first time the first step's target appears. |
176
271
  | `steps` | `TourStep[]` | Sequence of highlight steps. |
177
272
 
178
- ### DapScrollView
179
- A direct drop-in replacement for the React Native `ScrollView`. Supports all standard props, and a `ref` is forwarded to the inner `ScrollView`.
180
- | Property | Type | Description |
181
- |:---|:---|:---|
182
- | `children` | `React.Node` | Components to scroll. |
183
- | `...props` | `ScrollViewProps` | Standard props are forwarded to the native ScrollView. |
184
-
185
- ### DapTarget
186
- | Property | Type | Description |
187
- |:---|:---|:---|
188
- | `name` | `string` | Unique identifier that matches a `targetId` in a tour step. |
189
- | `children` | `ReactElement` | The UI element to wrap and highlight. |
190
- | `...props` | `ViewProps` | All standard React Native `View` props are forwarded. |
191
-
192
273
  ### TourStep
193
274
  | Property | Type | Default | Description |
194
275
  |:---|:---|:---|:---|
195
- | `targetId` | `string` | — | Matches the `name` prop in `<DapTarget>`. |
276
+ | `targetId` | `string` | — | Matches the `name` prop of a `<TourTarget>`. |
196
277
  | `title` | `string` | — | Tooltip header. |
197
278
  | `description` | `string` | — | Tooltip body. |
198
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`. |
199
283
 
200
- ### `useDap()` Hook
201
- | Method | Description |
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. |
302
+
303
+ ### `useTour()` Hook
304
+ | Member | Description |
202
305
  |:---|:---|
203
306
  | `startTour(id, options?)` | Start a tour by ID. Does nothing if it was already seen, unless `{ force: true }`. |
204
307
  | `stopTour(markAsSeen?)`| End tour. Pass `false` to keep it unread. |
205
308
  | `nextStep()` / `prevStep()` | Manual step navigation. |
206
309
  | `resetTour(id)` | Mark a tour as unseen so it can show (and auto-start) again. |
207
310
  | `resetAll()` | Mark every tour as unseen. |
311
+ | `status` | `'idle'`, `'waiting'` (looking for the step's target) or `'active'`. |
208
312
  | `activeTour` | Current active tour object. |
209
313
  | `currentStepIndex` | Current step number (0-indexed). |
210
314
  | `seenTours` | `Record<string, boolean>` of tours already seen. |
211
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.
329
+
212
330
  ---
213
331
 
214
332
  ## 🤝 Contributing
@@ -221,7 +339,7 @@ npm run typecheck && npm run lint && npm test # what CI runs
221
339
  npm run build # outputs lib/ (CommonJS, ES modules, types)
222
340
  ```
223
341
 
224
- The `example/` app loads the library straight from `src/`, so changes show up without a build:
342
+ The `example/` app (React Native 0.88, React Navigation) loads the library straight from `src/`, so changes show up without a build:
225
343
 
226
344
  ```sh
227
345
  cd example && npm install
@@ -233,4 +351,4 @@ npm run ios # or: npm run android
233
351
 
234
352
  <p align="center">
235
353
  <b>rn-smart-tour</b> • Built with ❤️ for the React Native community.
236
- </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":[]}