GithubHelp home page GithubHelp logo

Comments (6)

Alex0jk avatar Alex0jk commented on June 29, 2024 2

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

from react-native-spotlight-tour.

hugoxiong5 avatar hugoxiong5 commented on June 29, 2024 2

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.

from react-native-spotlight-tour.

Oakyden avatar Oakyden commented on June 29, 2024

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

?

from react-native-spotlight-tour.

nodahikaru avatar nodahikaru commented on June 29, 2024

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

from react-native-spotlight-tour.

nodahikaru avatar nodahikaru commented on June 29, 2024

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

from react-native-spotlight-tour.

etch01 avatar etch01 commented on June 29, 2024

add a small timeout inside useEffect:

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

from react-native-spotlight-tour.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.