Skip to content

Commit d2b0e15

Browse files
committed
feat(CopilotStep): Add active flag to steps
1 parent 8a9e3da commit d2b0e15

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/components/ConnectedCopilotStep.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,41 @@ type Props = {
77
name: string,
88
text: string,
99
order: number,
10+
active?: boolean,
1011
_copilot: CopilotContext,
1112
children: React$Element
1213
};
1314

1415
class ConnectedCopilotStep extends Component<Props> {
16+
static defaultProps = {
17+
active: true,
18+
};
19+
1520
componentDidMount() {
21+
if (this.props.active) {
22+
this.register();
23+
}
24+
}
25+
26+
componentWillReceiveProps(nextProps) {
27+
if (nextProps.active !== this.props.active) {
28+
if (nextProps.active) {
29+
this.register();
30+
} else {
31+
this.unregister();
32+
}
33+
}
34+
}
35+
36+
componentWillUnmount() {
37+
this.unregister();
38+
}
39+
40+
setNativeProps(obj) {
41+
this.wrapper.setNativeProps(obj);
42+
}
43+
44+
register() {
1645
this.props._copilot.registerStep({
1746
name: this.props.name,
1847
text: this.props.text,
@@ -22,14 +51,10 @@ class ConnectedCopilotStep extends Component<Props> {
2251
});
2352
}
2453

25-
componentWillUnmount() {
54+
unregister() {
2655
this.props._copilot.unregisterStep(this.props.name);
2756
}
2857

29-
setNativeProps(obj) {
30-
this.wrapper.setNativeProps(obj);
31-
}
32-
3358
measure() {
3459
if (typeof __TEST__ !== 'undefined' && __TEST__) { // eslint-disable-line no-undef
3560
return new Promise(resolve => resolve({

0 commit comments

Comments
 (0)