Skip to content

Commit a8bf8e3

Browse files
committed
fix: touchend event
1 parent d8f5b67 commit a8bf8e3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/store/ChartAdapterStore.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -243,31 +243,32 @@ export default class ChartAdapterStore {
243243
chartNode &&
244244
this.scrollableChartParent &&
245245
!this.mainStore.state.isVerticalScrollEnabled &&
246-
e.touches.length === 1
246+
e.changedTouches.length === 1
247247
) {
248-
const { pageX, screenX, screenY } = e.touches[0];
248+
const { pageX, pageY } = e.changedTouches[0];
249249
if (['touchstart', 'touchend'].includes(e.type)) {
250-
this.touchValues = e.type === 'touchstart' ? { x: screenX, y: screenY } : { yOnTouchEnd: screenY };
250+
this.touchValues = e.type === 'touchstart' ? { x: pageX, y: pageY } : { yOnTouchEnd: pageY };
251251
} else if (e.type === 'touchmove') {
252252
const nonScrollableAreaWidth = chartNode.offsetWidth - this.mainStore.chart.yAxisWidth;
253253
const { left } = chartNode.getBoundingClientRect();
254254

255255
if (this.touchValues.x && this.touchValues.y) {
256-
const deltaX = Math.abs(screenX - this.touchValues.x);
257-
const deltaY = Math.abs(screenY - this.touchValues.y);
256+
const deltaX = Math.abs(pageX - this.touchValues.x);
257+
const deltaY = Math.abs(pageY - this.touchValues.y);
258258
const isVerticalScroll = deltaY > deltaX;
259259
const x = pageX - left;
260260
if (x < nonScrollableAreaWidth && isVerticalScroll && !this.scrollChartParentOnTouchTimer) {
261261
this.touchValues.yOnTouchEnd = undefined;
262262
this.scrollChartParentOnTouchTimer = setTimeout(() => {
263263
this.scrollableChartParent?.scrollBy({
264-
top: screenY - Number(this.touchValues.yOnTouchEnd ?? this.touchValues.y),
264+
top: pageY - Number(this.touchValues.yOnTouchEnd ?? this.touchValues.y),
265+
behavior: 'smooth',
265266
});
266267
this.scrollChartParentOnTouchTimer = undefined;
267-
}, 300);
268+
}, 100);
268269
}
269270
}
270-
this.touchValues = { x: screenX, y: screenY };
271+
this.touchValues = { x: pageX, y: pageY };
271272
}
272273
}
273274
}

0 commit comments

Comments
 (0)