Skip to content

Commit d4880bc

Browse files
author
Marek Rozmus
committed
Add separate method for mouse move and touch move
1 parent 02b98ef commit d4880bc

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

examples/webpack.config.dev.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ module.exports = {
3737
modules: true
3838
}
3939
},
40-
{ loader: 'postcss-loader' }
40+
{
41+
loader: 'postcss-loader',
42+
options: {
43+
config: {
44+
path: path.join(__dirname, 'src', 'examples')
45+
}
46+
}
47+
}
4148
]
4249
}
4350
]

src/SwipeableListItem.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,28 @@ class SwipeableListItem extends PureComponent {
102102
requestAnimationFrame(this.updatePosition);
103103
};
104104

105-
handleTouchMove = event => this.handleMove(event, event.targetTouches[0]);
105+
handleMouseMove = event => {
106+
if (this.dragStartedWithinItem()) {
107+
const { clientX, clientY } = event;
108+
109+
this.setDragDirection(clientX, clientY);
106110

107-
handleMouseMove = event => this.handleMove(event, event);
111+
if (this.isSwiping()) {
112+
event.stopPropagation();
113+
event.preventDefault();
108114

109-
handleMove = (event, { clientX, clientY }) => {
115+
const delta = clientX - this.dragStartPoint.x;
116+
if (this.shouldMoveItem(delta)) {
117+
this.left = delta;
118+
}
119+
}
120+
}
121+
};
122+
123+
handleTouchMove = event => {
110124
if (this.dragStartedWithinItem()) {
125+
const { clientX, clientY } = event.targetTouches[0];
126+
111127
this.setDragDirection(clientX, clientY);
112128

113129
if (!event.cancelable) {

0 commit comments

Comments
 (0)