-
-
Notifications
You must be signed in to change notification settings - Fork 430
Expand file tree
/
Copy pathConnectedCopilotStep.js
More file actions
73 lines (62 loc) · 1.67 KB
/
ConnectedCopilotStep.js
File metadata and controls
73 lines (62 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// @flow
import React, { Component } from 'react';
import type { CopilotContext } from '../types';
type Props = {
name: string,
text: string,
order: number,
imageSource: string,
extraComponent: React$Element,
_copilot: CopilotContext,
children: React$Element
};
class ConnectedCopilotStep extends Component<Props> {
componentDidMount() {
this.props._copilot.registerStep({
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,
});
}
componentWillUnmount() {
this.props._copilot.unregisterStep(this.props.name);
}
setNativeProps(obj) {
this.wrapper.setNativeProps(obj);
}
measure() {
if (typeof __TEST__ !== 'undefined' && __TEST__) { // eslint-disable-line no-undef
return new Promise(resolve => resolve({
x: 0, y: 0, width: 0, height: 0,
}));
}
return new Promise((resolve, reject) => {
const measure = () => {
// Wait until the wrapper element appears
if (this.wrapper.measure) {
this.wrapper.measure(
(ox, oy, width, height, x, y) => resolve({
x, y, width, height,
}),
reject,
);
} else {
requestAnimationFrame(measure);
}
};
requestAnimationFrame(measure);
});
}
render() {
const copilot = {
ref: (wrapper) => { this.wrapper = wrapper; },
onLayout: () => { }, // Android hack
};
return React.cloneElement(this.props.children, { copilot });
}
}
export default ConnectedCopilotStep;