react-native-spotlight-tour icon indicating copy to clipboard operation
react-native-spotlight-tour copied to clipboard

Start tour programmatically

Open ghost opened this issue 3 years ago • 11 comments

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! :)

ghost avatar Jan 04 '22 12:01 ghost

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>
      ....
    )
  }

Alex0jk avatar Jan 06 '22 22:01 Alex0jk

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.

hugoxiong5 avatar Dec 27 '22 18:12 hugoxiong5

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

?

Oakyden avatar Aug 03 '23 11:08 Oakyden

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 avatar Aug 10 '23 04:08 nodahikaru

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

nodahikaru avatar Aug 10 '23 04:08 nodahikaru

add a small timeout inside useEffect:

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

etch01 avatar Aug 30 '23 18:08 etch01

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

Same on me.....

thvbb avatar Apr 25 '24 04:04 thvbb

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: https://github.com/mohebifar/react-native-copilot/issues/287#issuecomment-1697112964

bryanprimus avatar Apr 28 '24 12:04 bryanprimus

Please help me ~~~~

thvbb avatar May 02 '24 09:05 thvbb

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?

bryanprimus avatar May 02 '24 10:05 bryanprimus

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>
      ....
    )
  }

Not working on android. And animations are slow. App crash with error: Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

[[24,24,24,24,24,24,24],[19,16,9,20,19,17,12],[[],[121,1],[],[36],[],[599,"onTransitionProgress",4]],2019]

sufian1999 avatar Aug 02 '24 12:08 sufian1999