From b16b6c8d6a75c83fe2eef020989f1106bbdebeec Mon Sep 17 00:00:00 2001 From: Brian Rosamilia Date: Fri, 9 Oct 2020 18:42:45 -0400 Subject: [PATCH 1/2] add touch events for brush component --- packages/visx-brush/src/BaseBrush.tsx | 14 ++++++++++++++ packages/visx-brush/src/BrushHandle.tsx | 3 +++ packages/visx-brush/src/BrushSelection.tsx | 12 ++++++++++++ packages/visx-drag/src/Drag.tsx | 2 ++ 4 files changed, 31 insertions(+) diff --git a/packages/visx-brush/src/BaseBrush.tsx b/packages/visx-brush/src/BaseBrush.tsx index d5088d546..f865dbf72 100644 --- a/packages/visx-brush/src/BaseBrush.tsx +++ b/packages/visx-brush/src/BaseBrush.tsx @@ -376,6 +376,7 @@ export default class BaseBrush extends React.Component + {/* resize */} {({ dragStart, isDragging, dragMove, dragEnd }) => ( { + this.mouseDownTime = Date.now(); + dragStart(event); + }} + onTouchMove={(event: MouseHandlerEvent) => { + if (!isDragging && onMouseMove) onMouseMove(event); + if (isDragging) dragMove(event); + }} + onTouchEnd={(event: MouseHandlerEvent) => { + this.mouseUpTime = Date.now(); + if (onMouseUp) onMouseUp(event); + dragEnd(event); + }} style={BRUSH_OVERLAY_STYLES} /> )} diff --git a/packages/visx-brush/src/BrushHandle.tsx b/packages/visx-brush/src/BrushHandle.tsx index 03dcab37a..696de4240 100644 --- a/packages/visx-brush/src/BrushHandle.tsx +++ b/packages/visx-brush/src/BrushHandle.tsx @@ -144,6 +144,9 @@ export default class BrushHandle extends React.Component { onMouseDown={dragStart} onMouseMove={dragMove} onMouseUp={dragEnd} + onTouchStart={dragStart} + onTouchMove={dragMove} + onTouchEnd={dragEnd} style={{ cursor, pointerEvents: !!brush.activeHandle || !!brush.isBrushing ? 'none' : 'all', diff --git a/packages/visx-brush/src/BrushSelection.tsx b/packages/visx-brush/src/BrushSelection.tsx index 5dc028dee..8ff22bf9c 100644 --- a/packages/visx-brush/src/BrushSelection.tsx +++ b/packages/visx-brush/src/BrushSelection.tsx @@ -112,6 +112,7 @@ export default class BrushSelection extends React.Component< onDragMove={this.selectionDragMove} onDragEnd={this.selectionDragEnd} > + {/* location */} {({ isDragging, dragStart, dragEnd, dragMove }) => ( {isDragging && ( @@ -122,6 +123,8 @@ export default class BrushSelection extends React.Component< onMouseUp={dragEnd} onMouseMove={dragMove} onMouseLeave={dragEnd} + onTouchMove={dragMove} + onTouchEnd={dragEnd} style={DRAGGING_OVERLAY_STYLES} /> )} @@ -146,6 +149,15 @@ export default class BrushSelection extends React.Component< onClick={event => { if (onClick) onClick(event); }} + onTouchStart={disableDraggingSelection ? undefined : dragStart} + onTouchMove={event => { + dragMove(event); + if (onMouseMove) onMouseMove(event); + }} + onTouchEnd={event => { + dragEnd(event); + if (onMouseUp) onMouseUp(event); + }} style={{ pointerEvents: brush.isBrushing || brush.activeHandle ? 'none' : 'all', cursor: disableDraggingSelection ? undefined : 'move', diff --git a/packages/visx-drag/src/Drag.tsx b/packages/visx-drag/src/Drag.tsx index 1ccd95971..498f57882 100644 --- a/packages/visx-drag/src/Drag.tsx +++ b/packages/visx-drag/src/Drag.tsx @@ -120,6 +120,8 @@ export default class Drag extends React.Component { height={height} onMouseMove={this.handleDragMove} onMouseUp={this.handleDragEnd} + onTouchMove={this.handleDragMove} + onTouchEnd={this.handleDragEnd} fill="transparent" /> )} From 92ecd66ed0700f77b1f4e5032d674556a2cbd8cb Mon Sep 17 00:00:00 2001 From: Brian Rosamilia Date: Fri, 9 Oct 2020 20:49:01 -0400 Subject: [PATCH 2/2] remove comments --- packages/visx-brush/src/BaseBrush.tsx | 1 - packages/visx-brush/src/BrushSelection.tsx | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/visx-brush/src/BaseBrush.tsx b/packages/visx-brush/src/BaseBrush.tsx index f865dbf72..eaa51c00c 100644 --- a/packages/visx-brush/src/BaseBrush.tsx +++ b/packages/visx-brush/src/BaseBrush.tsx @@ -376,7 +376,6 @@ export default class BaseBrush extends React.Component - {/* resize */} {({ dragStart, isDragging, dragMove, dragEnd }) => ( - {/* location */} {({ isDragging, dragStart, dragEnd, dragMove }) => ( {isDragging && (