React Native · Components
Tour
Product tour (onboarding): highlights elements on screen one by one and shows a description card next to them.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Tour
componentProduct tour (onboarding): highlights elements on screen one by one and shows a description card next to them. Same steps and behavior as the web Tour; targets are given by TourTarget name or ref instead of a CSS selector.
- Highlight: The target's surroundings are dimmed; on step change the highlight slides to the new target. With a
scrolltracker, an off-screen target is scrolled into view and the highlight and card follow the element while scrolling. - Placement: The card sits on the side where it fits (
side) and draws an arrow pointing at the target (calculation shared with web). On phones the card sticks to the bottom of the screen; swiping left/right changes steps. - Persistence: With
storageKey(+storage) a finished tour never opens again and an interrupted one resumes. - Flexible steps:
onEntercan open a screen or wait for data before a step; a target rendered later is waited for.advanceOnClickwrites "press this" steps. - Accessibility: The card is announced like a modal window and progress is read on step change; the Android back button closes the tour.
- Looks the same on iOS and Android; opens in the library's own layer.
Examples
TourTarget
componentMarks content by name for Tour steps. Native counterpart of an element found by CSS selector on web: a step highlights this element with target: "search". It does not block touches on the content; in advanceOnClick steps pressing the content advances the tour.
Examples
TOUR_AUTO
constant"auto" order of the Tour card: below first, then above, then the sides.
placeCard
functionComputes the card position. Picks the first of the tried positions that fits on screen; if none fits, picks the one that overflows least and clamps it into the screen. Without a target the card is centered.
getTourState
functionReads the state of a tour saved with storageKey (same record format as web). Use it to show a "Restart tour" option in a "Help" menu or to open the tour only for new users. storage must be the same store given to Tour.
Examples
resetTour
functionDeletes the saved tour; the tour starts over on the next launch (or when a Tour rendered with storageKey remounts). Changing the key is also enough to change the tour's version ("welcome-v2").
Examples
TourRect
interfaceA rectangle on screen (relative to the viewport).
| Name | Type | Description |
|---|---|---|
x | number | Left edge. |
y | number | Top edge. |
width | number | Width. |
height | number | Height. |
TourViewport
interfaceSize of the viewport.
| Name | Type | Description |
|---|---|---|
width | number | Width. |
height | number | Height. |
TourPlacement
typePosition of the card relative to the target (same names as Placement on web and native): "auto", a side ("bottom") or a side and alignment ("bottom-left", "right-top").
CardPosition
interfaceComputed position of the card.
| Name | Type | Description |
|---|---|---|
x | number | Left edge of the card. |
y | number | Top edge of the card. |
side | TourSide | null | Side of the target the card sits on; null when centered. |
arrow | number | null | Distance of the arrow along the card edge. null when no arrow is drawn (when the card had to overlap the target or there is no target). |
TourStatus
typeSaved state of a tour.
"new": never shown."active": left halfway (the app closed or the user navigated away)."completed": went through to the last step."dismissed": the user skipped or closed the tour.
TourState
interfaceSaved state and, if left halfway, the step reached.
| Name | Type | Description |
|---|---|---|
status | TourStatus | Status. See TourStatus. |
step | number | Index of the step reached (starts at 0). |
TourTargetRef
typeThe element a step highlights:
- A name: an element marked with
TourTarget("search"). If the element renders later it is waited for;advanceOnClickworks only with this. - A
Viewref obtained withuseRef. - A function returning the element (called on every attempt).
If omitted the step appears as a card in the middle of the screen without a highlight (for welcome and closing steps).
TourTargetProps
interfaceProps of the TourTarget component.
| Name | Type | Description |
|---|---|---|
name | string | Name used in a step's target field. Must be unique in the app. |
children? | ReactNode | Content to highlight. |
style? | StyleProp<ViewStyle> | Style of the wrapper (e.g. alignSelf: "flex-start"). |
TourStepContext
interfaceValues a step's content receives when given as a function.
| Name | Type | Description |
|---|---|---|
index | number | Index of the shown step (starting at 0). |
total | number | Total number of steps. |
next | () => void | Moves to the next step; finishes the tour on the last step. |
back | () => void | Returns to the previous step. |
goTo | (index: number) => void | Goes to the step at the given index. |
close | () => void | Closes the tour (counts as skipped). |
TourStep
interfaceA step of Tour (same fields as web).
| Name | Type | Default | Description |
|---|---|---|---|
id? | string | Step id; for onStepChange and logs. | |
target? | TourTargetRef | Element to highlight: a TourTarget name ("search"), a View ref or a function returning the element. If omitted the card appears in the middle of the screen without a highlight (welcome and closing steps). See TourTargetRef. | |
title? | ReactNode | Title; screen readers announce the card with this name. | |
content? | ReactNode | ((context: TourStepContext) => ReactNode) | Description. A function receives TourStepContext; you can use your own buttons (e.g. "Try it now") in the content. | |
media? | ReactNode | Image or video shown edge to edge at the top of the card. | |
icon? | IconProp | Icon next to the title: a name or an element. | |
side? | TourPlacement | the Tour's `side | Position of the card relative to the target. |
padding? | number | the Tour's `padding | Gap the highlight leaves around the element (dp). |
radius? | number | the Tour's `radius | Corner radius of the highlight (dp). |
interactive? | boolean | false` (`true` when `advanceOnClick` is given) | Can the highlighted element be touched? When off, the whole screen blocks touches. |
advanceOnClick? | boolean | false | Move to the next step when the highlighted element is pressed? For "press this button" steps; the target must be given by its TourTarget name. |
nextLabel? | ReactNode | Label of the Next button in this step (e.g. "Let's start"). | |
hideBack? | boolean | false | Hides the Back button in this step. |
onEnter? | () => void | Promise<void> | Called before the step is shown: to open a menu, switch tabs or load data. If it returns a Promise the Next button shows loading until it settles and the step is shown afterwards. | |
onLeave? | () => void | Called when leaving the step (moving to another step or closing the tour). | |
scroll? | boolean | true | If the target is off screen, should it be scrolled into view with the Tour's scroll tracker? |
style? | ViewStyle | Style of this step's card. |
Why the tour closed (same as web).
"close": Close (×) or the "Skip" button on the first step."escape": Not used on native (the Esc key on web)."overlay": Tapping the dimmed area (closeOnOverlayClick)."back": Android back button.
TourProgress
typeProgress indicator: "dots" dots, "count" "2 / 5", "bar" a thin bar at the top of the card, "none" nothing. "auto" shows dots up to 7 steps and a count beyond.
TourLabels
interfaceButton and screen reader texts of Tour.
| Name | Type | Default | Description |
|---|---|---|---|
next | string | Defaults to the UIProvider text ("İleri" in Turkish). | |
back | string | Defaults to the UIProvider text ("Geri" in Turkish). | |
done | string | Button on the last step. Defaults to the UIProvider text ("Bitir" in Turkish). | |
skip | string | Button in place of Back on the first step. Defaults to the UIProvider text ("Geç" in Turkish). | |
close | string | Name of the Close (×) button. Defaults to the UIProvider text ("Turu kapat" in Turkish). | |
progress | (step: number, total: number) => string | (step, total) => "2 / 5" | Progress text. |
TourStyles
interfaceStyles of the Tour inner parts.
| Name | Type | Description |
|---|---|---|
card? | ViewStyle | Card. |
spotlight? | ViewStyle | Highlight (the hole with dimmed surroundings, or a frame). |
media? | ViewStyle | Media area of the card. |
footer? | ViewStyle | Bottom row holding the buttons. |
TourProps
interfaceProps of the Tour component (same names as web).
| Name | Type | Default | Description |
|---|---|---|---|
steps | readonly TourStep[] | Steps. See TourStep. | |
open? | boolean | Whether the tour is open, in controlled use. | |
defaultOpen? | boolean | true` if `storageKey` is given, otherwise `false | Should the tour start by itself when the screen opens? Defaults to true when storageKey is given: the tour starts only if it was not finished or skipped before. |
onOpenChange? | (open: boolean) => void | Called with the new state when it opens or closes. | |
step? | number | Index of the shown step in controlled use (starting at 0). | |
defaultStep? | number | 0 | Initial step in uncontrolled use. |
onStepChange? | (index: number, step: TourStep) => void | Called with the new index and step when the step changes. | |
onComplete? | () => void | Called when Finish is pressed on the last step. | |
onDismiss? | (index: number, reason: TourDismissReason) => void | Called with the step reached and the reason when the tour is closed before finishing. | |
storageKey? | string | Name under which the tour is remembered. When given, a finished or skipped tour never opens by itself again; an interrupted tour resumes from its step. Pass storage to make it persistent. See getTourState, resetTour. | |
storage? | PreferenceStorage | Where the state is stored (a @yasinsensoy/native/storage store can be passed directly). If omitted it is forgotten when the app closes. | |
resume? | boolean | true | Should a tour interrupted with storageKey resume from its step? |
scroll? | ScrollTracker | Tracker of the scroll area the targets live in (useScrollTracker). When given, an off-screen target is scrolled into view and the highlight follows the element as the user scrolls. | |
side? | TourPlacement | "auto" | Default position of the card relative to the target. |
padding? | number | 8 | Gap of the highlight around the element (dp). |
radius? | number | 10 | Corner radius of the highlight (dp). |
mask? | boolean | true | Dim the target's surroundings? When off, only a colored frame appears around the target. |
progress? | TourProgress | "auto" | Progress indicator. See TourProgress. |
dismissible? | boolean | true | Can the user close the tour (×, "Skip", back button)? When off, the tour only closes by finishing. |
closeOnOverlayClick? | boolean | false | Close the tour when the dimmed area is tapped? |
closeOnBackButton? | boolean | true | Should the Android back button close the tour? |
missingTarget? | "center" | "skip" | "center" | What to do if the target is not found? "center" shows the card in the middle; "skip" skips the step. |
targetTimeout? | number | 1500 | If the target has not rendered yet (e.g. a screen opened in onEnter), how long to wait at most (ms)? |
mobileDock? | boolean | true | On phones (below 640 dp), should the card stick to the bottom of the screen (to the top if the target is at the bottom)? The card can be swiped left/right to change steps. |
labels? | Partial<TourLabels> | Texts. See TourLabels. | |
styles? | TourStyles | Styles of the inner parts. See TourStyles. | |
testID? | string | Test id (given to the card). |