Skip to content

Commit f91d892

Browse files
author
Pedro
committed
Add skip event listener
1 parent 5b4b8f2 commit f91d892

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ Along with `this.props.start()`, `copilot` HOC passes `copilotEvents` function t
184184
List of available events is:
185185

186186
- `start` — Copilot tutorial has started.
187-
- `stop` — Copilot tutorial has ended or skipped.
187+
- `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)
188+
- `stop` — Copilot tutorial has ended.
188189
- `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.
189190

190191

src/components/CopilotModal.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Props = {
99
stop: () => void,
1010
next: () => void,
1111
prev: () => void,
12+
skip: () => void,
1213
currentStepNumber: number,
1314
currentStep: ?Step,
1415
visible: boolean,
@@ -217,6 +218,11 @@ class CopilotModal extends Component<Props, State> {
217218
this.props.stop();
218219
}
219220

221+
handleSkip = () => {
222+
this.reset();
223+
this.props.skip();
224+
}
225+
220226
renderMask() {
221227
/* eslint-disable global-require */
222228
const MaskComponent = this.props.overlay === 'svg'
@@ -270,6 +276,7 @@ class CopilotModal extends Component<Props, State> {
270276
handleNext={this.handleNext}
271277
handlePrev={this.handlePrev}
272278
handleStop={this.handleStop}
279+
handleSkip={this.handleSkip}
273280
/>
274281
</Animated.View>,
275282
];

src/hocs/copilot.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ const copilot = ({
147147
}
148148
}
149149

150+
skip = async (): void => {
151+
await this.setVisibility(false);
152+
this.eventEmitter.emit('skip', {
153+
currentStep: this.state.currentStep,
154+
nextStep: this.getNextStep()
155+
});
156+
}
157+
150158
stop = async (): void => {
151159
await this.setVisibility(false);
152160
this.eventEmitter.emit('stop');
@@ -177,6 +185,7 @@ const copilot = ({
177185
next={this.next}
178186
prev={this.prev}
179187
stop={this.stop}
188+
skip={this.skip}
180189
visible={this.state.visible}
181190
isFirstStep={this.isFirstStep()}
182191
isLastStep={this.isLastStep()}

0 commit comments

Comments
 (0)