Open vrinch opened 3 years ago
hey @vrinch. I have used it like this:
tour
context file. For example in context/
folder. In it, I've added:import React from 'react';
import { useTourGuideController } from 'rn-tourguide';
const withTourHOC = (Component: any) => {
return (props: any) => {
const {
canStart, // a boolean indicate if you can start tour guide
start, // a function to start the tourguide
stop, // a function to stopping it
eventEmitter, // an object for listening some events
} = useTourGuideController();
return <Component
tourCanStart={canStart}
tourStart={start}
tourStop={stop}
tourEventEmitter={eventEmitter}
{...props} />;
};
};
export { withTourHOC };
Imported that context file in App
main component:
import { withTourHOC } from 'src/context/tour';
Used it as HOC for App component:
export default withTourHOC(App);
Used it in App
as follows:
in componentDidMount
:
this.props.tourEventEmitter.on('start', () => console.log('start'));
this.props.tourEventEmitter.on('stop', () => console.log('stop'));
this.props.tourEventEmitter.on('stepChange', () => console.log(`stepChange`));
in componentDidUpdate
:
if (prevProps.tourCanStart !== this.props.tourCanStart && this.props.tourCanStart) {
this.props.tourStart();
}
in componentWillUnmount
:
this.props.tourEventEmitter.off('*', null);
Hope this helps 😄
I followed the instructions, but encountered an error “this.props.tourEventEmitter.on is undefined”. How can I resolve this?
I followed the instructions, but encountered an error “this.props.tourEventEmitter.on is undefined”. How can I resolve this?
I have also encountered this problem.
I have solved this problem, you need to wrap the corresponding Class Component with a Provider.
Is it possible you could provide a working example for for class component as my entire project was built with it and I’d like to implement an app tour instead of the regular onboarding process.