Skip to content

Commit 5b4b8f2

Browse files
authored
Merge pull request #54 from naffiq/docs/events
Described event emitters in readme
2 parents 9b10293 + 7c96141 commit 5b4b8f2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,40 @@ class HomeScreen {
178178
### Triggering the tutorial
179179
Use `this.props.start()` in the root component in order to trigger the tutorial. You can either invoke it with a touch event or in `componentDidMount`. Note that the component and all its descendants must be mounted before starting the tutorial since the `CopilotStep`s need to be registered first.
180180

181+
### Listening to the events
182+
Along with `this.props.start()`, `copilot` HOC passes `copilotEvents` function to the component to help you with tracking of tutorial progress. It utilizes [mitt](https://github.com/developit/mitt) under the hood, you can see how full API there.
183+
184+
List of available events is:
185+
186+
- `start` — Copilot tutorial has started.
187+
- `stop` — Copilot tutorial has ended or skipped.
188+
- `stepChange` — Next step is triggered. Passes [`Step`](https://github.com/okgrow/react-native-copilot/blob/master/src/types.js#L2) instance as event handler argument.
189+
190+
191+
**Example:**
192+
```js
193+
import { copilot, CopilotStep } from '@okgrow/react-native-copilot';
194+
195+
const CustomComponent = ({ copilot }) => <View {...copilot}><Text>Hello world!</Text></View>;
196+
197+
class HomeScreen {
198+
componentDidMount() {
199+
this.props.copilotEvents.on('stop', () => {
200+
// Copilot tutorial finished!
201+
});
202+
}
203+
204+
componentWillUnmount() {
205+
// Don't forget to disable event handlers to prevent errors
206+
this.props.copilotEvents.off('stop');
207+
}
208+
209+
render() {
210+
// ...
211+
}
212+
}
213+
```
214+
181215
## Contributing
182216
Issues and Pull Requests are always welcome.
183217

0 commit comments

Comments
 (0)