Skip to content

Commit f939d3e

Browse files
committed
exclude the StepNumber into its own component and made it replaceable via props
1 parent 493e532 commit f939d3e

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

src/components/CopilotModal.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React, { Component } from 'react';
33
import { Animated, Easing, View, Text, 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,25 @@ class CopilotModal extends Component<Props, State> {
235238
}
236239

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

240243
return [
241244
<Animated.View
242245
key="stepNumber"
243246
style={[
244-
styles.stepNumber,
247+
styles.stepNumberContainer,
245248
{
246249
left: this.state.animatedValues.stepNumberLeft,
247250
top: Animated.add(this.state.animatedValues.top, -STEP_NUMBER_RADIUS),
248251
},
249252
]}
250253
>
251-
<Text style={[styles.stepNumberText]}>{this.props.currentStepNumber}</Text>
254+
<StepNumberComponent
255+
isFirstStep={this.props.isFirstStep}
256+
isLastStep={this.props.isLastStep}
257+
currentStep={this.props.currentStep}
258+
currentStepNumber={this.props.currentStepNumber}
259+
/>
252260
</Animated.View>,
253261
<Animated.View key="arrow" style={[styles.arrow, this.state.arrow]} />,
254262
<Animated.View key="tooltip" style={[styles.tooltip, this.state.tooltip]}>

src/components/StepNumber.js

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

src/components/style.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,21 @@ export default StyleSheet.create({
3636
tooltipContainer: {
3737
flex: 1,
3838
},
39-
stepNumber: {
39+
stepNumberContainer: {
4040
position: 'absolute',
4141
width: STEP_NUMBER_DIAMETER,
4242
height: STEP_NUMBER_DIAMETER,
43-
borderWidth: 2,
44-
borderRadius: STEP_NUMBER_RADIUS,
45-
borderColor: '#FFFFFF',
46-
backgroundColor: '#27ae60',
4743
overflow: 'hidden',
4844
alignItems: 'center',
4945
justifyContent: 'center',
5046
zIndex: ZINDEX + 1,
5147
},
48+
stepNumber: {
49+
borderWidth: 2,
50+
borderRadius: STEP_NUMBER_RADIUS,
51+
borderColor: '#FFFFFF',
52+
backgroundColor: '#27ae60',
53+
},
5254
stepNumberText: {
5355
fontSize: 10,
5456
backgroundColor: 'transparent',

src/hocs/copilot.js

Lines changed: 3 additions & 1 deletion
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
} = {}) =>
@@ -160,7 +161,7 @@ const copilot = ({
160161

161162
componentWillUnmount() {
162163
this.mounted = false;
163-
};
164+
}
164165

165166
render() {
166167
return (
@@ -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)