Giter Site home page Giter Site logo

Comments (4)

alexandrumic avatar alexandrumic commented on May 3, 2024 2

hey @vrinch. I have used it like this:

  1. Created a 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 };
  1. Imported that context file in App main component:
import { withTourHOC } from 'src/context/tour';
  1. Used it as HOC for App component:
export default withTourHOC(App);
  1. 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 😄

from rn-tourguide.

beidaoxiangcai avatar beidaoxiangcai commented on May 3, 2024

I followed the instructions, but encountered an error “this.props.tourEventEmitter.on is undefined”. How can I resolve this?

from rn-tourguide.

Yang9322 avatar Yang9322 commented on May 3, 2024

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.

from rn-tourguide.

Yang9322 avatar Yang9322 commented on May 3, 2024

I have solved this problem, you need to wrap the corresponding Class Component with a Provider.

from rn-tourguide.

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.