Skip to content

Commit 7bbeefc

Browse files
author
Pedro
committed
Add skip event listener
1 parent 07795e7 commit 7bbeefc

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
@@ -148,6 +148,14 @@ const copilot = ({
148148
}
149149
}
150150

151+
skip = async (): void => {
152+
await this.setVisibility(false);
153+
this.eventEmitter.emit('skip', {
154+
currentStep: this.state.currentStep,
155+
nextStep: this.getNextStep()
156+
});
157+
}
158+
151159
stop = async (): void => {
152160
await this.setVisibility(false);
153161
this.eventEmitter.emit('stop');
@@ -178,6 +186,7 @@ const copilot = ({
178186
next={this.next}
179187
prev={this.prev}
180188
stop={this.stop}
189+
skip={this.skip}
181190
visible={this.state.visible}
182191
isFirstStep={this.isFirstStep()}
183192
isLastStep={this.isLastStep()}

0 commit comments

Comments
 (0)