Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an 'allowSkip' prop to disable the skip button if desired #187

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ You can customize the tooltip by passing a component to the `copilot` HOC maker.

```js
const TooltipComponent = ({
allowSkip,
isFirstStep,
isLastStep,
handleNext,
Expand Down
2 changes: 2 additions & 0 deletions src/components/CopilotModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Props = {
currentStepNumber: number,
currentStep: ?Step,
visible: boolean,
allowSkip: boolean,
isFirstStep: boolean,
isLastStep: boolean,
easing: ?func,
Expand Down Expand Up @@ -283,6 +284,7 @@ class CopilotModal extends Component<Props, State> {
<Animated.View key="arrow" style={[styles.arrow, this.state.arrow]} />,
<Animated.View key="tooltip" style={[styles.tooltip, this.state.tooltip, this.props.tooltipStyle]}>
<TooltipComponent
allowSkip={this.props.allowSkip}
isFirstStep={this.props.isFirstStep}
isLastStep={this.props.isLastStep}
currentStep={this.props.currentStep}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import styles from './style';
import type { Step } from '../types';

type Props = {
allowSkip: boolean,
isFirstStep: boolean,
isLastStep: boolean,
handleNext: func,
Expand All @@ -19,6 +20,7 @@ type Props = {
};

const Tooltip = ({
allowSkip,
isFirstStep,
isLastStep,
handleNext,
Expand All @@ -33,7 +35,7 @@ const Tooltip = ({
</View>
<View style={[styles.bottomBar]}>
{
!isLastStep ?
(!isLastStep && allowSkip) ?
<TouchableOpacity onPress={handleStop}>
<Button>{labels.skip || 'Skip'}</Button>
</TouchableOpacity>
Expand Down
2 changes: 2 additions & 0 deletions src/hocs/copilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const copilot = ({
svgMaskPath,
verticalOffset = 0,
wrapperStyle,
allowSkip = true,
} = {}) =>
(WrappedComponent) => {
class Copilot extends Component<any, State> {
Expand Down Expand Up @@ -204,6 +205,7 @@ const copilot = ({
prev={this.prev}
stop={this.stop}
visible={this.state.visible}
allowSkip={allowSkip}
isFirstStep={this.isFirstStep()}
isLastStep={this.isLastStep()}
currentStepNumber={this.getStepNumber()}
Expand Down
1 change: 1 addition & 0 deletions src/hocs/copilot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ it('shows the custom tooltip component if specified', async () => {
const tooltip = tree.root.findByType(TooltipComponent);

expect(tooltip).toBeDefined();
expect(tooltip.props).toHaveProperty('allowSkip');
expect(tooltip.props).toHaveProperty('currentStep');
expect(tooltip.props).toHaveProperty('handlePrev');
expect(tooltip.props).toHaveProperty('handleNext');
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare module '@okgrow/react-native-copilot' {
};

export type CopilotTooltipProps = {
allowSkip: boolean;
isFirstStep: boolean;
isLastStep: boolean;
handleNext: () => void;
Expand Down