Comments (6)
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 auseEffect
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.
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.
Is there not a way to do this just this with const { start } = useSpotlightTour();
?
from react-native-spotlight-tour.
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 auseEffect
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.
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.
add a small timeout inside useEffect:
setTimeout(()=>{
spotlightRef.current?.start();
},100)
from react-native-spotlight-tour.
Related Issues (20)
- Update all-contributors contributions HOT 9
- Support for tour steps that have no spot (no AttachStep) HOT 2
- React is not defined HOT 5
- Use WebPack to build and serve the Web version of the example
- Documentation url broken HOT 4
- Suggestion: Add name/key property to AttachStep instead of index HOT 1
- Question: How use ScrollView in SpotlightTourProvider HOT 2
- Spotlight Covering Whole Screen
- Jump Tour Steps HOT 2
- Document that react-native-spotlight-tour also works on react-native-web HOT 3
- TourBox is undocumented or at least not mentioned on the front page readme HOT 2
- Warpping functional components in AttachStep doesn't seem to work HOT 1
- Android Layout Problem with 2.0 HOT 4
- Crash on Android (Expo 47): "attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference" HOT 7
- Spotlight style/shape HOT 2
- Tutorial Content is not align correctly. [bug] HOT 7
- Cant find React variable in some file HOT 4
- Prepare actions for the stop event by using onStop property HOT 1
- Support React Native Web HOT 1
- Setup all-contributors on the project HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-spotlight-tour.