rn-smart-tour 2.0.0 → 2.1.0-rc.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 (111) hide show
  1. package/README.md +88 -7
  2. package/lib/commonjs/core/TourEngine.js +271 -32
  3. package/lib/commonjs/core/TourEngine.js.map +1 -1
  4. package/lib/commonjs/core/controller.js +2 -0
  5. package/lib/commonjs/core/controller.js.map +1 -1
  6. package/lib/commonjs/core/measure.js +4 -3
  7. package/lib/commonjs/core/measure.js.map +1 -1
  8. package/lib/commonjs/index.js +14 -0
  9. package/lib/commonjs/index.js.map +1 -1
  10. package/lib/commonjs/react/TourOverlay.js +106 -59
  11. package/lib/commonjs/react/TourOverlay.js.map +1 -1
  12. package/lib/commonjs/react/TourOverlayHost.js +4 -1
  13. package/lib/commonjs/react/TourOverlayHost.js.map +1 -1
  14. package/lib/commonjs/react/TourProvider.js +31 -5
  15. package/lib/commonjs/react/TourProvider.js.map +1 -1
  16. package/lib/commonjs/react/TourScrollable.js +50 -4
  17. package/lib/commonjs/react/TourScrollable.js.map +1 -1
  18. package/lib/commonjs/react/accessibility.js +39 -0
  19. package/lib/commonjs/react/accessibility.js.map +1 -0
  20. package/lib/commonjs/react/context.js +7 -1
  21. package/lib/commonjs/react/context.js.map +1 -1
  22. package/lib/commonjs/react/hooks.js +1 -0
  23. package/lib/commonjs/react/hooks.js.map +1 -1
  24. package/lib/commonjs/react-navigation.js +122 -2
  25. package/lib/commonjs/react-navigation.js.map +1 -1
  26. package/lib/module/core/TourEngine.js +270 -32
  27. package/lib/module/core/TourEngine.js.map +1 -1
  28. package/lib/module/core/controller.js +2 -0
  29. package/lib/module/core/controller.js.map +1 -1
  30. package/lib/module/core/measure.js +4 -3
  31. package/lib/module/core/measure.js.map +1 -1
  32. package/lib/module/index.js +2 -2
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/react/TourOverlay.js +106 -59
  35. package/lib/module/react/TourOverlay.js.map +1 -1
  36. package/lib/module/react/TourOverlayHost.js +5 -2
  37. package/lib/module/react/TourOverlayHost.js.map +1 -1
  38. package/lib/module/react/TourProvider.js +32 -6
  39. package/lib/module/react/TourProvider.js.map +1 -1
  40. package/lib/module/react/TourScrollable.js +51 -5
  41. package/lib/module/react/TourScrollable.js.map +1 -1
  42. package/lib/module/react/accessibility.js +33 -0
  43. package/lib/module/react/accessibility.js.map +1 -0
  44. package/lib/module/react/context.js +6 -0
  45. package/lib/module/react/context.js.map +1 -1
  46. package/lib/module/react/hooks.js +1 -0
  47. package/lib/module/react/hooks.js.map +1 -1
  48. package/lib/module/react-navigation.js +119 -3
  49. package/lib/module/react-navigation.js.map +1 -1
  50. package/lib/typescript/commonjs/src/core/TourEngine.d.ts +60 -2
  51. package/lib/typescript/commonjs/src/core/TourEngine.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/src/core/controller.d.ts +8 -1
  53. package/lib/typescript/commonjs/src/core/controller.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/src/core/measure.d.ts +2 -1
  55. package/lib/typescript/commonjs/src/core/measure.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/src/index.d.ts +3 -3
  57. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/src/react/TourOverlay.d.ts +9 -1
  59. package/lib/typescript/commonjs/src/react/TourOverlay.d.ts.map +1 -1
  60. package/lib/typescript/commonjs/src/react/TourOverlayHost.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/src/react/TourProvider.d.ts +9 -0
  62. package/lib/typescript/commonjs/src/react/TourProvider.d.ts.map +1 -1
  63. package/lib/typescript/commonjs/src/react/TourScrollable.d.ts +24 -1
  64. package/lib/typescript/commonjs/src/react/TourScrollable.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/src/react/accessibility.d.ts +5 -0
  66. package/lib/typescript/commonjs/src/react/accessibility.d.ts.map +1 -0
  67. package/lib/typescript/commonjs/src/react/context.d.ts +5 -0
  68. package/lib/typescript/commonjs/src/react/context.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/src/react/hooks.d.ts.map +1 -1
  70. package/lib/typescript/commonjs/src/react-navigation.d.ts +63 -0
  71. package/lib/typescript/commonjs/src/react-navigation.d.ts.map +1 -1
  72. package/lib/typescript/commonjs/src/types.d.ts +27 -0
  73. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  74. package/lib/typescript/module/src/core/TourEngine.d.ts +60 -2
  75. package/lib/typescript/module/src/core/TourEngine.d.ts.map +1 -1
  76. package/lib/typescript/module/src/core/controller.d.ts +8 -1
  77. package/lib/typescript/module/src/core/controller.d.ts.map +1 -1
  78. package/lib/typescript/module/src/core/measure.d.ts +2 -1
  79. package/lib/typescript/module/src/core/measure.d.ts.map +1 -1
  80. package/lib/typescript/module/src/index.d.ts +3 -3
  81. package/lib/typescript/module/src/index.d.ts.map +1 -1
  82. package/lib/typescript/module/src/react/TourOverlay.d.ts +9 -1
  83. package/lib/typescript/module/src/react/TourOverlay.d.ts.map +1 -1
  84. package/lib/typescript/module/src/react/TourOverlayHost.d.ts.map +1 -1
  85. package/lib/typescript/module/src/react/TourProvider.d.ts +9 -0
  86. package/lib/typescript/module/src/react/TourProvider.d.ts.map +1 -1
  87. package/lib/typescript/module/src/react/TourScrollable.d.ts +24 -1
  88. package/lib/typescript/module/src/react/TourScrollable.d.ts.map +1 -1
  89. package/lib/typescript/module/src/react/accessibility.d.ts +5 -0
  90. package/lib/typescript/module/src/react/accessibility.d.ts.map +1 -0
  91. package/lib/typescript/module/src/react/context.d.ts +5 -0
  92. package/lib/typescript/module/src/react/context.d.ts.map +1 -1
  93. package/lib/typescript/module/src/react/hooks.d.ts.map +1 -1
  94. package/lib/typescript/module/src/react-navigation.d.ts +63 -0
  95. package/lib/typescript/module/src/react-navigation.d.ts.map +1 -1
  96. package/lib/typescript/module/src/types.d.ts +27 -0
  97. package/lib/typescript/module/src/types.d.ts.map +1 -1
  98. package/package.json +18 -4
  99. package/src/core/TourEngine.ts +293 -31
  100. package/src/core/controller.ts +9 -0
  101. package/src/core/measure.ts +6 -2
  102. package/src/index.ts +3 -3
  103. package/src/react/TourOverlay.tsx +99 -49
  104. package/src/react/TourOverlayHost.tsx +4 -2
  105. package/src/react/TourProvider.tsx +36 -4
  106. package/src/react/TourScrollable.tsx +61 -4
  107. package/src/react/accessibility.ts +39 -0
  108. package/src/react/context.ts +9 -0
  109. package/src/react/hooks.ts +1 -0
  110. package/src/react-navigation.tsx +156 -1
  111. package/src/types.ts +24 -0
package/README.md CHANGED
@@ -106,6 +106,27 @@ const OrdersScreen = () => (
106
106
 
107
107
  Not using React Navigation? `TourScope` does the same with an `active` prop you control: `<TourScope active={isVisible}>`.
108
108
 
109
+ **Drawer.** Drawer content stays mounted, off-screen, while the drawer is closed. Wrap it in `DrawerTourScope` so its targets only count once the drawer has finished sliding open (React Navigation drawer v6/v7; no extra dependencies). For a drawer that is always shown (`drawerType: 'permanent'`), pass `permanent`.
110
+
111
+ ```tsx
112
+ import { DrawerTourScope, useStartTourAfterDrawerClose } from 'rn-smart-tour/react-navigation';
113
+
114
+ const DrawerContent = (props: DrawerContentComponentProps) => {
115
+ // "App Tour" in the menu: start once the drawer has slid away, so the tour never dims it mid-slide.
116
+ const startAfterClose = useStartTourAfterDrawerClose(props.navigation);
117
+ const replay = () => {
118
+ startAfterClose('dashboard', { force: true });
119
+ props.navigation.closeDrawer();
120
+ };
121
+
122
+ return (
123
+ <DrawerTourScope navigation={props.navigation} permanent={isWideTablet}>
124
+ <DrawerContentScrollView {...props}>{/* items with TourTargets */}</DrawerContentScrollView>
125
+ </DrawerTourScope>
126
+ );
127
+ };
128
+ ```
129
+
109
130
  ### 5. Lists (Optional)
110
131
  To let tours scroll a target into view, use `TourScrollView` instead of `ScrollView`, or wrap a `FlatList` / `SectionList` in `TourScrollable`:
111
132
 
@@ -127,7 +148,32 @@ const listRef = useRef<FlatList>(null);
127
148
  </TourScrollable>
128
149
  ```
129
150
 
130
- A target in a virtualized list can only be scrolled to once its row has rendered.
151
+ **Lists inside lists.** Wrap each scroll container (e.g. a horizontal row of cards inside a vertical page). The tour scrolls the innermost one first, then each one around it, so the target ends up on screen:
152
+
153
+ ```tsx
154
+ <TourScrollView>
155
+ <TourScrollable scrollRef={cardsRef} horizontal>
156
+ <FlatList ref={cardsRef} horizontal … />
157
+ </TourScrollable>
158
+ </TourScrollView>
159
+ ```
160
+
161
+ **Items that aren't rendered yet.** A `FlatList` only renders the items near the screen. To point a step at an item further down, name the list and give the step the item's index: if the item isn't rendered when the step starts, the list is scrolled to it first.
162
+
163
+ ```tsx
164
+ <TourScrollable scrollRef={listRef} name="customers">
165
+ <FlatList
166
+ ref={listRef}
167
+ onScrollToIndexFailed={scrollToIndexFailedHandler(listRef)} // only without getItemLayout
168
+ …
169
+ />
170
+ </TourScrollable>
171
+
172
+ // in the tour
173
+ { targetId: 'customer-40', title: '…', description: '…', scrollToIndex: { list: 'customers', index: 40 } }
174
+ ```
175
+
176
+ A `FlatList` without `getItemLayout` can't jump straight to an item it hasn't measured; `scrollToIndexFailedHandler` (exported by the library) jumps close using the average item size and tries again. FlashList needs neither.
131
177
 
132
178
  ### 6. Tours Across Screens (Optional)
133
179
  `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.
@@ -176,6 +222,16 @@ const mmkvAdapter = {
176
222
 
177
223
  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.
178
224
 
225
+ **One set per user.** By default the device keeps one set of seen tours, so on a shared or handed-over device the next person never sees them. Pass the signed-in user's id:
226
+
227
+ ```tsx
228
+ <TourProvider tours={TOURS} storageAdapter={mmkvAdapter} userId={employee?.id ?? null}>
229
+ ```
230
+
231
+ Each user's seen tours are stored separately. When `userId` changes (sign-in, sign-out, another user), a running tour ends without being marked seen and the new user's seen tours are loaded; calls made meanwhile are queued as above. The first user on a device that already has seen tours stored without a user takes those over, so an existing user isn't shown every tour again after the upgrade; later users start fresh. Outside React: `createTourController({ userId })` and `controller.setUserId(id)`.
232
+
233
+ **Show a changed tour again.** Give a tour a `version` and raise it when its content changes enough to show again. A tour is seen only if the version the user saw is at least the current one. A tour without `version` counts as version 1, so adding `version: 1` changes nothing and `version: 2` shows it once more.
234
+
179
235
  ### 8. Your Own Tooltip Card (Optional)
180
236
  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.
181
237
 
@@ -286,7 +342,7 @@ Pass `onEvent` to see how tours perform: how many users finish each walkthrough,
286
342
  <TourProvider tours={TOURS} onEvent={event => analyticsQueue.push(event)}>
287
343
  ```
288
344
 
289
- Every event has `type`, `runId` (the same for every event of one run of a tour, start to end), `tourId`, `tourKind` and `timestamp`, plus:
345
+ Every event has `type`, `eventId` (unique: drop duplicates when a batch is uploaded again after a failed request), `runId` (the same for every event of one run of a tour, start to end), `tourId`, `tourKind` and `timestamp`, plus:
290
346
 
291
347
  | `type` | When | Extra fields |
292
348
  |:---|:---|:---|
@@ -303,6 +359,23 @@ Every event has `type`, `runId` (the same for every event of one run of a tour,
303
359
 
304
360
  ---
305
361
 
362
+ ### 13. Accessibility
363
+ Works with VoiceOver and TalkBack and the system "reduce motion" setting, with nothing to set up:
364
+
365
+ - **Each step is announced** when it appears (once per step, not again when it is re-measured): title, description, what to do on an action step, and "Step 2 of 5". This also covers custom cards. To translate or change it, pass `getStepAnnouncement`; return `null` to say nothing for a step:
366
+
367
+ ```tsx
368
+ <TourProvider
369
+ tours={TOURS}
370
+ getStepAnnouncement={({ step, stepIndex, stepCount }) =>
371
+ t('tour.announcement', { title: step.title, text: step.description, n: stepIndex + 1, total: stepCount })
372
+ }>
373
+ ```
374
+
375
+ `defaultStepAnnouncement(props)` is the built-in text, if you only want to add to it.
376
+ - On iOS, VoiceOver stays inside the overlay while a step is shown. The built-in card marks its title as a heading and its buttons as buttons, and reads the position as "Step 2 of 5".
377
+ - **Reduce motion** (iOS Reduce Motion, Android "Remove animations"): the overlay appears without fading in, and targets are scrolled into view without animating.
378
+
306
379
  ## 🧠 Technical Architecture
307
380
 
308
381
  <details>
@@ -331,7 +404,7 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
331
404
  <details>
332
405
  <summary><b>Tour Lifecycle Rules</b></summary>
333
406
 
334
- - **Skip**, **Finish** and the **Android back button** end the tour and mark it as seen.
407
+ - **Skip**, **Finish** and the **Android back button** end the tour and mark it as seen. The tour takes the back button only while a step is shown (otherwise it goes to the app as usual), ahead of the app's own back handlers, including ones a screen added during the tour. For a step inside an app popup, back goes to the popup (its `onRequestClose`): the popup closes, and the step's target is then missing as usual: a walkthrough pauses with the Resume chip, a tour ends unseen.
335
408
  - 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, moves to the next step with `onMissingTarget: 'skip'`, or pauses with a Resume chip with `onMissingTarget: 'pause'` (the default for walkthroughs). A warning is logged in development.
336
409
  - 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.
337
410
  - 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.
@@ -347,6 +420,7 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
347
420
  |:---|:---|:---|:---|
348
421
  | `tours` | `Record<string, Tour>` | — | All tours, keyed by id. |
349
422
  | `storageAdapter` | `StorageAdapter` | — | Persists seen tours (AsyncStorage, MMKV, …). Read once on mount. |
423
+ | `userId` | `string \| null` | — | The signed-in user: each user has their own seen tours. Changing it ends a running tour (unseen) and loads the new user's. See [Remember Seen Tours](#7-remember-seen-tours-optional). |
350
424
  | `missingTargetTimeoutMs` | `number` | `3000` | How long a step waits for its target. |
351
425
  | `controller` | `TourController` | — | From `createTourController`, instead of `tours` / `storageAdapter`. |
352
426
  | `renderTooltip` | `(props: TourTooltipProps) => ReactNode` | built-in card | Draws the tooltip card. Receives the step, its index and count, and `next` / `prev` / `skip`. |
@@ -359,12 +433,14 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
359
433
  | `onEvent` | `(event: TourEvent) => void` | — | Analytics: every start, step shown, completion, exit (and why), block, pause, resume and missing target. See [Analytics](#12-analytics-optional). |
360
434
  | `renderResumeChip` | `(props: ResumeChipProps) => ReactNode` | built-in chip | Draws the "Resume" chip shown while a tour is paused (`tour`, `resume`, `dismiss`). |
361
435
  | `highlightColor` | `string` | `'#FFFFFF'` | Ring around an element the user should tap. |
436
+ | `getStepAnnouncement` | `(props: TourTooltipProps) => string \| null` | `defaultStepAnnouncement` | What screen readers say when a step appears. See [Accessibility](#13-accessibility). |
362
437
 
363
438
  ### Tour Configuration
364
439
  | Property | Type | Description |
365
440
  |:---|:---|:---|
366
441
  | `id` | `string` | Unique identifier for caching. |
367
442
  | `autoStart` | `boolean` | Start the first time the first step with a target appears. |
443
+ | `version` | `number` | Content version (from 1). Raise it to show a changed tour again to users who saw an older one. |
368
444
  | `steps` | `TourStep[]` | Sequence of highlight steps. |
369
445
  | `kind` | `'tour' \| 'walkthrough'` | Walkthroughs pause on a missing target and say "Exit". Default `'tour'`. |
370
446
  | `title` / `description` / `keywords` | `string` / `string` / `string[]` | Shown and searched by `useTourCatalog`. |
@@ -383,6 +459,7 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
383
459
  | `when` | `(context) => boolean` | — | Show the step only when this returns true. |
384
460
  | `onMissingTarget` | `'end' \| 'skip' \| 'pause'` | `'end'` (`'pause'` for walkthroughs) | What happens if the target isn't found in time. |
385
461
  | `targetTimeoutMs` | `number` | provider's | Per-step override of `missingTargetTimeoutMs`. |
462
+ | `scrollToIndex` | `{ list, index }` | — | The target is item `index` of the list named `list` (`TourScrollable name`): if it isn't rendered, the list is scrolled to it first. |
386
463
 
387
464
  ### TourTarget
388
465
  | Property | Type | Description |
@@ -401,11 +478,14 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
401
478
  |:---|:---|:---|
402
479
  | `TourScope` | `active?: boolean` (default `true`) | Targets inside only count while `active` (and every parent scope is active). |
403
480
  | `NavigationTourScope` | — | From `rn-smart-tour/react-navigation`. Active while the screen is focused and not animating. |
481
+ | `DrawerTourScope` | `navigation`, `permanent?` | From `rn-smart-tour/react-navigation`. For drawer content: active once the drawer has finished opening, inactive as it starts to close; always active when `permanent`. |
482
+
483
+ `useStartTourAfterDrawerClose(navigation, { fallbackMs? })` (also from `rn-smart-tour/react-navigation`) returns `(tourId, options?) => void`: it starts the tour once the drawer has finished closing, or after `fallbackMs` (default 600) if the drawer reports no close. Call it, then close the drawer or navigate.
404
484
 
405
485
  ### TourScrollable / TourScrollView
406
486
  | Component | Props | Description |
407
487
  |:---|:---|:---|
408
- | `TourScrollable` | `scrollRef`, `horizontal?` | Lets tours scroll targets inside the referenced `ScrollView` / `FlatList` / `SectionList`. |
488
+ | `TourScrollable` | `scrollRef`, `horizontal?`, `name?` | Lets tours scroll targets inside the referenced `ScrollView` / `FlatList` / `SectionList`. Nested ones are scrolled innermost first. `name` is for steps with `scrollToIndex`. |
409
489
  | `TourScrollView` | `ScrollViewProps` | A `ScrollView` already wrapped in `TourScrollable`. A `ref` is forwarded. |
410
490
 
411
491
  ### `useTour()` Hook
@@ -422,6 +502,7 @@ A tour that is stopped (finished, skipped, or ended because a target was missing
422
502
  | `seenTours` | `Record<string, boolean>` of tours already seen. |
423
503
  | `emit(event)` | Report an app event, for steps with `advanceOn: { event }`. |
424
504
  | `pauseTour()` / `resumeTour()` | Put the running tour on hold / continue it. |
505
+ | `setUserId(id)` | Switch whose seen tours are used (same as changing the provider's `userId`). |
425
506
 
426
507
  `useTourState(selector)` subscribes to any slice of the tour state and re-renders only when it changes.
427
508
 
@@ -442,9 +523,9 @@ Behaviour changes:
442
523
 
443
524
  ## ⚠️ Known Limitations
444
525
 
445
- - **Nested lists**: only a target's nearest scroll container is scrolled. A target in a horizontal row inside a vertical list is brought into view sideways, but the outer list doesn't scroll to the row.
446
- - **Sliding elements**: a target moved by a transform animation (a drawer or sheet sliding in) is measured once it holds still for 3 frames, or after 600 ms. Put such targets in a `TourScope` that becomes active once the animation has finished (e.g. a drawer's progress reaching 1).
447
- - **Virtualized lists**: `FlatList` items that aren't rendered yet can't be highlighted.
526
+ - **Scroll containers must be wrapped**: only containers wrapped in `TourScrollable` / `TourScrollView` are scrolled.
527
+ - **Sliding elements**: a target moved by a transform animation (a sheet sliding in) is measured once it holds still for 3 frames, or after 600 ms. Put such targets in a `TourScope` that becomes active once the animation has finished. For a React Navigation drawer, use `DrawerTourScope`.
528
+ - **Items that aren't rendered yet**: reachable with a step's `scrollToIndex` when you know the item's index; otherwise only once the item has rendered.
448
529
 
449
530
  ---
450
531