Skip to content

Commit b132e7f

Browse files
Simplify drawing fixture
1 parent 9bdee33 commit b132e7f

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

fixtures/dom/src/components/fixtures/pointer-events/draw-box.js

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,39 @@ class DrawBox extends React.Component {
44
state = {
55
isDrawing: false,
66
isCapturing: false,
7-
isOver: false,
8-
x: 0,
9-
y: 0,
107
};
118

129
el = React.createRef();
1310

1411
onDown = event => {
15-
this.setState({
16-
isDrawing: true,
17-
...this.extractRelativeCoordinates(event),
18-
});
12+
this.setState({isDrawing: true});
1913

2014
this.el.current.setPointerCapture(event.pointerId);
15+
16+
const {x, y} = this.extractRelativeCoordinates(event);
17+
18+
const ctx = this.el.current.getContext('2d');
19+
ctx.beginPath();
20+
ctx.moveTo(x, y);
2121
};
2222

2323
onMove = event => {
2424
if (!this.state.isDrawing) {
2525
return;
2626
}
2727

28-
const nextState = this.extractRelativeCoordinates(event);
28+
const {x, y} = this.extractRelativeCoordinates(event);
2929

3030
const ctx = this.el.current.getContext('2d');
31-
ctx.beginPath();
32-
ctx.moveTo(this.state.x, this.state.y);
33-
ctx.lineTo(nextState.x, nextState.y);
31+
ctx.lineTo(x, y);
3432
ctx.stroke();
35-
ctx.closePath();
36-
37-
this.setState(nextState);
3833
};
3934

4035
onUp = event => {
41-
this.setState({
42-
isDrawing: false,
43-
});
44-
};
45-
46-
onOver = event => {
47-
this.setState({isOver: true});
48-
};
36+
this.setState({isDrawing: false});
4937

50-
onOut = event => {
51-
this.setState({isOver: false});
38+
const ctx = this.el.current.getContext('2d');
39+
ctx.closePath();
5240
};
5341

5442
onGotCapture = event => {
@@ -69,10 +57,10 @@ class DrawBox extends React.Component {
6957
};
7058

7159
render() {
72-
const {isOver, isCapturing} = this.state;
60+
const {isCapturing} = this.state;
7361

7462
const boxStyle = {
75-
border: `1px solid ${isCapturing ? 'blue' : isOver ? 'red' : '#d9d9d9'}`,
63+
border: `1px solid ${isCapturing ? 'blue' : '#d9d9d9'}`,
7664
margin: '10px 0 20px',
7765
touchAction: 'none',
7866
};
@@ -87,8 +75,6 @@ class DrawBox extends React.Component {
8775
onPointerMove={this.onMove}
8876
onPointerUp={this.onUp}
8977
onPointerCancel={this.onUp}
90-
onPointerOver={this.onOver}
91-
onPointerOut={this.onOut}
9278
onGotPointerCapture={this.onGotCapture}
9379
onLostPointerCapture={this.onLostCapture}
9480
/>

fixtures/dom/src/components/fixtures/pointer-events/drawing.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ class Drawing extends React.Component {
1212
</TestCase.Steps>
1313

1414
<TestCase.ExpectedResult>
15-
You should see strokes as you move the pointer tool. While your
16-
pointer tool is over the canvas, it should also have a red border.
17-
While drawing, the canvas must have a blue border to signalize that a
18-
pointer capture was received.
15+
You should see strokes as you move the pointer tool. While drawing,
16+
the canvas must have a blue border to signalize that a pointer capture
17+
was received.
1918
</TestCase.ExpectedResult>
2019

2120
<DrawBox />

0 commit comments

Comments
 (0)