From 08d0017aadcb3f2b4d74eb6a863bb917e25cab95 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 30 Jul 2018 16:18:00 +0100 Subject: [PATCH] Add information about the skipped step --- README.md | 2 +- src/components/CopilotModal.js | 6 ++++-- src/hocs/copilot.js | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) 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 {