Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start tour programmatically #50

Open
ghost opened this issue Jan 4, 2022 · 10 comments
Open

Start tour programmatically #50

ghost opened this issue Jan 4, 2022 · 10 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ghost
Copy link

ghost commented Jan 4, 2022

Hello, thanks for this great package

Is there a way to begin the tour without calling start() via on onpress?

For example, I want my tour to automatically start the first time the user opens the app

Thanks! :)

@Alex0jk
Copy link
Contributor

Alex0jk commented Jan 6, 2022

Hi @cacode-euan, thanks for bringing this up. This is possible but you'll have to work your way around to achieve it. I think this is a great feature so we'll add it to our pipeline to work on it. In the meantime, these are the options you could use:

  • You can call start() inside the rendering of the component after you have access to the function you need. In case you want to start the tour on load; start() would be called inside a useEffect there.

  • You can use a ref and call the start function with it. Again, if you want to start the tour on screen load, you can use a useEffect. This could look something like this:

  export const App: React.FC = () => {
    ....
    const refTour = React.createRef<SpotlightTour>();
    ....
    useEffect(() => {
     refTour.current?.start();
    });
    
    return (
      ...
      <SpotlightTourProvider
        steps={tourSteps}
        ....
        ref={refTour}
      >
       ....
      </SpotlightTourProvider>
      ....
    )
  }

@JoseLion JoseLion added enhancement New feature or request question Further information is requested labels Jan 6, 2022
@JoseLion JoseLion removed the question Further information is requested label Sep 29, 2022
@hugoxiong5
Copy link

Hey, thanks for this solution.

However, to prevent re-renders in my functional component, instead of React.createRef, I switched to a useRef<SpotlightTour>(null) hook. This seems to work nicely.

@JoseLion JoseLion added the help wanted Extra attention is needed label Apr 24, 2023
@Oakyden
Copy link

Oakyden commented Aug 3, 2023

Is there not a way to do this just this with const { start } = useSpotlightTour();

?

@nodahikaru
Copy link

nodahikaru commented Aug 10, 2023

Hi @cacode-euan, thanks for bringing this up. This is possible but you'll have to work your way around to achieve it. I think this is a great feature so we'll add it to our pipeline to work on it. In the meantime, these are the options you could use:

  • You can call start() inside the rendering of the component after you have access to the function you need. In case you want to start the tour on load; start() would be called inside a useEffect there.
  • You can use a ref and call the start function with it. Again, if you want to start the tour on screen load, you can use a useEffect. This could look something like this:
  export const App: React.FC = () => {
    ....
    const refTour = React.createRef<SpotlightTour>();
    ....
    useEffect(() => {
     refTour.current?.start();
    });
    
    return (
      ...
      <SpotlightTourProvider
        steps={tourSteps}
        ....
        ref={refTour}
      >
       ....
      </SpotlightTourProvider>
      ....
    )
  }

@nodahikaru
Copy link

I need to start tour programmatically and used SpotlightTour ref and useEffect.
But it doesn't show tour, only backdrop

@etch01
Copy link

etch01 commented Aug 30, 2023

add a small timeout inside useEffect:

setTimeout(()=>{
            spotlightRef.current?.start();
},100)

@thvbb
Copy link

thvbb commented Apr 25, 2024

I need to start tour programmatically and used SpotlightTour ref and useEffect. But it doesn't show tour, only backdrop

Same on me.....

@bryanltobing
Copy link

I need to start tour programmatically and used SpotlightTour ref and useEffect.
But it doesn't show tour, only backdrop

i'm able to solve this using onLayout. feels more proper than setting up the timeout

<View onLayout={() => start()}>

source: mohebifar/react-native-copilot#287 (comment)

@thvbb
Copy link

thvbb commented May 2, 2024

Please help me ~~~~

@bryanltobing
Copy link

bryanltobing commented May 2, 2024

I call start() inside a useEffect, but its worked with react-native-web, not worked in react-native-app

have you tried any of the workaround above?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

8 participants