diff --git a/README.md b/README.md index 604189a9..90acf03a 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ Along with `this.props.start()`, `copilot` HOC passes `copilotEvents` function t List of available events is: - `start` — Copilot tutorial has started. -- `stop` — Copilot tutorial has ended or skipped. +- `stop` — Copilot tutorial has ended. - `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. diff --git a/src/components/CopilotModal.js b/src/components/CopilotModal.js index 2339a838..8ce17c34 100644 --- a/src/components/CopilotModal.js +++ b/src/components/CopilotModal.js @@ -212,9 +212,11 @@ class CopilotModal extends Component { this.props.prev(); } - handleStop = () => { + handleStop = (wasSkipped?: boolean) => { + wasSkipped = typeof wasSkipped !== "boolean" ? false : wasSkipped; + this.reset(); - this.props.stop(); + this.props.stop(wasSkipped); } renderMask() { diff --git a/src/hocs/copilot.js b/src/hocs/copilot.js index 0da1c028..48469691 100644 --- a/src/hocs/copilot.js +++ b/src/hocs/copilot.js @@ -148,9 +148,19 @@ const copilot = ({ } } - stop = async (): void => { + stop = async (wasSkipped: boolean): void => { await this.setVisibility(false); - this.eventEmitter.emit('stop'); + this.eventEmitter.emit('stop', wasSkipped + ? { + wasSkipped: true, + skippedStep: this.state.currentStep, + nextStep: this.getNextStep() + } + : { + wasSkipped: false, + skippedStep: null, + nextStep: null + }); } async moveToCurrentStep(): void {