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

Feat: Support image in tooltip #40

Open
wants to merge 4 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Every `CopilotStep` must have these props:
1. **name**: A unique name for the walkthrough step.
2. **order**: A positive number indicating the order of the step in the entire walkthrough.
3. **text**: The text shown as the description for the step.
4. **imageSource(optional)**: Image to be shown on the tooltip of walkthrough step.
5. **extraComponent(optional)**: Any other custom React component or React element to be shown in the tooltip of walkthrough step.

In order to start the tutorial, you can call the `start` prop function in the root component that is injected by `copilot`:

Expand Down
4 changes: 4 additions & 0 deletions src/components/ConnectedCopilotStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type Props = {
name: string,
text: string,
order: number,
imageSource: string,
extraComponent: React$Element,
_copilot: CopilotContext,
children: React$Element
};
Expand All @@ -17,6 +19,8 @@ class ConnectedCopilotStep extends Component<Props> {
name: this.props.name,
text: this.props.text,
order: this.props.order,
imageSource: this.props.imageSource,
extraComponent: this.props.extraComponent,
target: this,
wrapper: this.wrapper,
});
Expand Down
72 changes: 40 additions & 32 deletions src/components/Tooltip.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { View, Text, Image, TouchableOpacity } from 'react-native';

import Button from './Button';

Expand All @@ -24,37 +24,45 @@ const Tooltip = ({
handlePrev,
handleStop,
currentStep,
}: Props) => (
<View>
<View style={styles.tooltipContainer}>
<Text testID="stepDescription" style={styles.tooltipText}>{currentStep.text}</Text>
}: Props) => {
return (
<View>
<View style={styles.extraComponentContainer}>
{currentStep.extraComponent}
</View>
<View style={styles.imageContainer}>
<Image style={{ flex: 1 }} source={currentStep.imageSource} />
</View>
<View style={styles.tooltipContainer}>
<Text testID="stepDescription" style={styles.tooltipText}>{currentStep.text}</Text>
</View>
<View style={[styles.bottomBar]}>
{
!isLastStep ?
<TouchableOpacity onPress={handleStop}>
<Button>Skip</Button>
</TouchableOpacity>
: null
}
{
!isFirstStep ?
<TouchableOpacity onPress={handlePrev}>
<Button>Previous</Button>
</TouchableOpacity>
: null
}
{
!isLastStep ?
<TouchableOpacity onPress={handleNext}>
<Button>Next</Button>
</TouchableOpacity> :
<TouchableOpacity onPress={handleStop}>
<Button>Finish</Button>
</TouchableOpacity>
}
</View>
</View>
<View style={[styles.bottomBar]}>
{
!isLastStep ?
<TouchableOpacity onPress={handleStop}>
<Button>Skip</Button>
</TouchableOpacity>
: null
}
{
!isFirstStep ?
<TouchableOpacity onPress={handlePrev}>
<Button>Previous</Button>
</TouchableOpacity>
: null
}
{
!isLastStep ?
<TouchableOpacity onPress={handleNext}>
<Button>Next</Button>
</TouchableOpacity> :
<TouchableOpacity onPress={handleStop}>
<Button>Finish</Button>
</TouchableOpacity>
}
</View>
</View>
);
)
};

export default Tooltip;
10 changes: 10 additions & 0 deletions src/components/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export default StyleSheet.create({
},
tooltipText: {

},
extraComponentContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
imageContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
tooltipContainer: {
flex: 1,
Expand Down