Skip to content

Commit

Permalink
Add information about skipped step
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro committed Aug 11, 2018
1 parent 7bbeefc commit 7f7ca95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ Along with `this.props.start()`, `copilot` HOC passes `copilotEvents` function t
List of available events is:

- `start` — Copilot tutorial has started.
- `skip` — Copilot tutorial has skipped. Passes and object with currentStep and nextStep information. Both are instances of [`Step`](https://github.com/okgrow/react-native-copilot/blob/master/src/types.js#L2)
- `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.

Expand Down
10 changes: 3 additions & 7 deletions src/components/CopilotModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type Props = {
stop: () => void,
next: () => void,
prev: () => void,
skip: () => void,
currentStepNumber: number,
currentStep: ?Step,
visible: boolean,
Expand Down Expand Up @@ -213,14 +212,11 @@ class CopilotModal extends Component<Props, State> {
this.props.prev();
}

handleStop = () => {
this.reset();
this.props.stop();
}
handleStop = (wasSkipped?: boolean) => {
wasSkipped = typeof wasSkipped !== "boolean" ? false : wasSkipped;

handleSkip = () => {
this.reset();
this.props.skip();
this.props.stop(wasSkipped);
}

renderMask() {
Expand Down
21 changes: 11 additions & 10 deletions src/hocs/copilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ const copilot = ({
}
}

skip = async (): void => {
stop = async (wasSkipped: boolean): void => {
await this.setVisibility(false);
this.eventEmitter.emit('skip', {
currentStep: this.state.currentStep,
nextStep: this.getNextStep()
this.eventEmitter.emit('stop', wasSkipped
? {
wasSkipped: true,
skippedStep: this.state.currentStep,
nextStep: this.getNextStep()
}
: {
wasSkipped: false,
skippedStep: null,
nextStep: null
});
}

stop = async (): void => {
await this.setVisibility(false);
this.eventEmitter.emit('stop');
}

async moveToCurrentStep(): void {
const size = await this.state.currentStep.target.measure();

Expand All @@ -186,7 +188,6 @@ const copilot = ({
next={this.next}
prev={this.prev}
stop={this.stop}
skip={this.skip}
visible={this.state.visible}
isFirstStep={this.isFirstStep()}
isLastStep={this.isLastStep()}
Expand Down

0 comments on commit 7f7ca95

Please sign in to comment.