Skip to content

Commit 9f2213a

Browse files
Anupriy Ranupriy97
authored andcommitted
2 parents b951927 + e635829 commit 9f2213a

File tree

6 files changed

+72
-19
lines changed

6 files changed

+72
-19
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ You can specify the overlay when applying the `copilot` HOC:
114114
```js
115115
copilot({
116116
overlay: 'svg', // or 'view'
117-
animated true, // or false
117+
animated: true, // or false
118118
})(RootComponent);
119119
```
120120

@@ -138,6 +138,24 @@ copilot({
138138
})(RootComponent)
139139
```
140140

141+
### Custom step number component
142+
You can customize the step number by passing a component to the `copilot` HOC maker. If you are looking for an example step number component, take a look at [the default step number implementation](https://github.com/okgrow/react-native-copilot/blob/master/src/components/StepNumber.js).
143+
144+
```js
145+
const StepNumberComponent = ({
146+
isFirstStep,
147+
isLastStep,
148+
currentStep,
149+
currentStepNumber,
150+
}) => (
151+
// ...
152+
);
153+
154+
copilot({
155+
stepNumberComponent: StepNumberComponent
156+
})(RootComponent)
157+
```
158+
141159
### Custom components as steps
142160
The components wrapped inside `CopilotStep`, will receive a `copilot` prop of type `Object` which the outermost rendered element of the component or the element that you want the tooltip be shown around, must extend.
143161

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@okgrow/react-native-copilot",
3-
"version": "2.2.6",
3+
"version": "2.3.0",
44
"description": "Make an interactive step by step tour guide for you react-native app",
55
"main": "src/index.js",
66
"private": false,

src/components/CopilotModal.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// @flow
22
import React, { Component } from 'react';
3-
import { Animated, Easing, View, Text, NativeModules, Modal, StatusBar, Platform } from 'react-native';
3+
import { Animated, Easing, View, NativeModules, Modal, StatusBar, Platform } from 'react-native';
44
import Tooltip from './Tooltip';
5+
import StepNumber from './StepNumber';
56
import styles, { MARGIN, ARROW_SIZE, STEP_NUMBER_DIAMETER, STEP_NUMBER_RADIUS } from './style';
67

78
type Props = {
@@ -16,6 +17,7 @@ type Props = {
1617
easing: ?func,
1718
animationDuration: ?number,
1819
tooltipComponent: ?React$Component,
20+
stepNumberComponent: ?React$Component,
1921
overlay: 'svg' | 'view',
2022
animated: boolean,
2123
androidStatusBarVisible: boolean,
@@ -39,6 +41,7 @@ class CopilotModal extends Component<Props, State> {
3941
easing: Easing.elastic(0.7),
4042
animationDuration: 400,
4143
tooltipComponent: Tooltip,
44+
stepNumberComponent: StepNumber,
4245
// If react-native-svg native module was avaialble, use svg as the default overlay component
4346
overlay: typeof NativeModules.RNSVGSvgViewManager !== 'undefined' ? 'svg' : 'view',
4447
// If animated was not specified, rely on the default overlay type
@@ -235,20 +238,28 @@ class CopilotModal extends Component<Props, State> {
235238
}
236239

237240
renderTooltip() {
238-
const { tooltipComponent: TooltipComponent } = this.props;
241+
const {
242+
tooltipComponent: TooltipComponent,
243+
stepNumberComponent: StepNumberComponent,
244+
} = this.props;
239245

240246
return [
241247
<Animated.View
242248
key="stepNumber"
243249
style={[
244-
styles.stepNumber,
250+
styles.stepNumberContainer,
245251
{
246252
left: this.state.animatedValues.stepNumberLeft,
247253
top: Animated.add(this.state.animatedValues.top, -STEP_NUMBER_RADIUS),
248254
},
249255
]}
250256
>
251-
<Text style={[styles.stepNumberText]}>{this.props.currentStepNumber}</Text>
257+
<StepNumberComponent
258+
isFirstStep={this.props.isFirstStep}
259+
isLastStep={this.props.isLastStep}
260+
currentStep={this.props.currentStep}
261+
currentStepNumber={this.props.currentStepNumber}
262+
/>
252263
</Animated.View>,
253264
<Animated.View key="arrow" style={[styles.arrow, this.state.arrow]} />,
254265
<Animated.View key="tooltip" style={[styles.tooltip, this.state.tooltip]}>

src/components/StepNumber.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @flow
2+
import React from 'react';
3+
import { View, Text } from 'react-native';
4+
5+
import styles from './style';
6+
7+
type Props = {
8+
currentStepNumber: number,
9+
};
10+
11+
const StepNumber = ({
12+
currentStepNumber,
13+
}: Props) => (
14+
<View style={styles.stepNumber}>
15+
<Text style={[styles.stepNumberText]}>{currentStepNumber}</Text>
16+
</View>
17+
);
18+
19+
export default StepNumber;

src/components/style.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,21 @@ export default StyleSheet.create({
4646
tooltipContainer: {
4747
flex: 1,
4848
},
49-
stepNumber: {
49+
stepNumberContainer: {
5050
position: 'absolute',
5151
width: STEP_NUMBER_DIAMETER,
5252
height: STEP_NUMBER_DIAMETER,
53+
overflow: 'hidden',
54+
zIndex: ZINDEX + 1,
55+
},
56+
stepNumber: {
57+
flex: 1,
58+
alignItems: 'center',
59+
justifyContent: 'center',
5360
borderWidth: 2,
5461
borderRadius: STEP_NUMBER_RADIUS,
5562
borderColor: '#FFFFFF',
5663
backgroundColor: '#27ae60',
57-
overflow: 'hidden',
58-
alignItems: 'center',
59-
justifyContent: 'center',
60-
zIndex: ZINDEX + 1,
6164
},
6265
stepNumberText: {
6366
fontSize: 10,

src/hocs/copilot.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type State = {
2929
const copilot = ({
3030
overlay,
3131
tooltipComponent,
32+
stepNumberComponent,
3233
animated,
3334
androidStatusBarVisible,
3435
} = {}) =>
@@ -50,6 +51,14 @@ const copilot = ({
5051
};
5152
}
5253

54+
componentDidMount() {
55+
this.mounted = true;
56+
}
57+
58+
componentWillUnmount() {
59+
this.mounted = false;
60+
}
61+
5362
getStepNumber = (step: ?Step = this.state.currentStep): number =>
5463
getStepNumber(this.state.steps, step);
5564

@@ -154,14 +163,6 @@ const copilot = ({
154163
});
155164
}
156165

157-
componentDidMount() {
158-
this.mounted = true;
159-
}
160-
161-
componentWillUnmount() {
162-
this.mounted = false;
163-
};
164-
165166
render() {
166167
return (
167168
<View style={{ flex: 1 }}>
@@ -181,6 +182,7 @@ const copilot = ({
181182
isLastStep={this.isLastStep()}
182183
currentStepNumber={this.getStepNumber()}
183184
currentStep={this.state.currentStep}
185+
stepNumberComponent={stepNumberComponent}
184186
tooltipComponent={tooltipComponent}
185187
overlay={overlay}
186188
animated={animated}

0 commit comments

Comments
 (0)