@@ -44,12 +44,10 @@ export default class ChartAdapterStore {
44
44
deltaYTotal ?: number ;
45
45
x ?: number ;
46
46
y ?: number ;
47
- yOnTouchEnd ?: number ;
48
47
} = {
49
48
deltaYTotal : 0 ,
50
49
x : 0 ,
51
50
y : 0 ,
52
- yOnTouchEnd : 0 ,
53
51
} ;
54
52
55
53
isOverFlutterCharts = false ;
@@ -243,21 +241,17 @@ export default class ChartAdapterStore {
243
241
}
244
242
245
243
onTouch ( e : TouchEvent ) {
246
- const chartNode = this . mainStore . chart . chartNode ;
247
244
// Prevent vertical scroll on the chart for touch devices by forcing scroll on a scrollable parent of the chart:
245
+ const chartNode = this . mainStore . chart . chartNode ;
248
246
if (
249
247
chartNode &&
250
248
this . scrollableChartParent &&
251
249
! this . mainStore . state . isVerticalScrollEnabled &&
252
250
e . changedTouches . length === 1
253
251
) {
254
252
const { pageX, pageY } = e . changedTouches [ 0 ] ;
255
- if ( [ 'touchstart' , 'touchend' ] . includes ( e . type ) ) {
256
- this . touchValues =
257
- e . type === 'touchstart'
258
- ? { x : pageX , y : pageY }
259
- : { yOnTouchEnd : pageY , deltaYTotal : this . touchValues . deltaYTotal } ;
260
- } else if ( e . type === 'touchmove' ) {
253
+
254
+ if ( [ 'touchmove' , 'touchend' ] . includes ( e . type ) ) {
261
255
const nonScrollableAreaWidth = chartNode . offsetWidth - this . mainStore . chart . yAxisWidth ;
262
256
const { left } = chartNode . getBoundingClientRect ( ) ;
263
257
@@ -267,20 +261,39 @@ export default class ChartAdapterStore {
267
261
this . touchValues . deltaYTotal = ( this . touchValues . deltaYTotal ?? 0 ) + ( this . touchValues . y - pageY ) ;
268
262
const isVerticalScroll = deltaY > deltaX ;
269
263
const x = pageX - left ;
270
- if ( x < nonScrollableAreaWidth && isVerticalScroll && ! this . scrollChartParentOnTouchTimer ) {
271
- this . touchValues . yOnTouchEnd = undefined ;
272
- this . scrollChartParentOnTouchTimer = setTimeout ( ( ) => {
273
- this . scrollableChartParent ?. scrollBy ( {
274
- top : this . touchValues . deltaYTotal ,
264
+ const isForcedScrollArea = x < nonScrollableAreaWidth ;
265
+ const shouldForceMaxScroll =
266
+ Math . abs ( Number ( this . touchValues . deltaYTotal ) ) > 10 && e . type === 'touchend' ;
267
+ if ( isForcedScrollArea ) {
268
+ if ( shouldForceMaxScroll ) {
269
+ clearTimeout ( this . scrollChartParentOnTouchTimer ) ;
270
+ this . scrollableChartParent ?. scrollTo ( {
271
+ top :
272
+ Number ( this . touchValues . deltaYTotal ) < 0
273
+ ? 0
274
+ : this . scrollableChartParent . scrollHeight ,
275
275
behavior : 'smooth' ,
276
276
} ) ;
277
277
this . scrollChartParentOnTouchTimer = undefined ;
278
278
this . touchValues = { ...this . touchValues , deltaYTotal : 0 } ;
279
- } , 100 ) ;
279
+ } else if ( isVerticalScroll && ! this . scrollChartParentOnTouchTimer ) {
280
+ this . scrollChartParentOnTouchTimer = setTimeout ( ( ) => {
281
+ this . scrollableChartParent ?. scrollBy ( {
282
+ top : this . touchValues . deltaYTotal ,
283
+ behavior : 'smooth' ,
284
+ } ) ;
285
+ this . scrollChartParentOnTouchTimer = undefined ;
286
+ this . touchValues = { ...this . touchValues , deltaYTotal : 0 } ;
287
+ } , 100 ) ;
288
+ }
280
289
}
281
290
}
282
291
this . touchValues = { ...this . touchValues , x : pageX , y : pageY } ;
283
292
}
293
+ if ( [ 'touchstart' , 'touchend' ] . includes ( e . type ) ) {
294
+ this . touchValues =
295
+ e . type === 'touchstart' ? { x : pageX , y : pageY } : { deltaYTotal : this . touchValues . deltaYTotal } ;
296
+ }
284
297
}
285
298
}
286
299
0 commit comments