Skip to content

Commit 04660e8

Browse files
authored
docs(events): described event emitters in readme
1 parent 9b10293 commit 04660e8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,35 @@ 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+
render() {
205+
// ...
206+
}
207+
}
208+
```
209+
181210
## Contributing
182211
Issues and Pull Requests are always welcome.
183212

0 commit comments

Comments
 (0)