@@ -58,10 +58,11 @@ export default class ChartAdapterStore {
58
58
59
59
isOverFlutterCharts = false ;
60
60
enableVerticalScrollTimer ?: ReturnType < typeof setTimeout > ;
61
- scrollChartParentOnTouchTimer ?: ReturnType < typeof setTimeout > ;
61
+ clearTouchDeltasTimer ?: ReturnType < typeof setTimeout > ;
62
62
63
63
constructor ( mainStore : MainStore ) {
64
64
makeObservable ( this , {
65
+ clearTouchDeltasTimer : observable ,
65
66
onMount : action . bound ,
66
67
onTickHistory : action . bound ,
67
68
onTouch : action . bound ,
@@ -75,7 +76,6 @@ export default class ChartAdapterStore {
75
76
enableVerticalScrollTimer : observable ,
76
77
scale : action . bound ,
77
78
scrollableChartParent : computed ,
78
- scrollChartParentOnTouchTimer : observable ,
79
79
toggleDataFitMode : action . bound ,
80
80
touchValues : observable ,
81
81
onCrosshairMove : action . bound ,
@@ -212,9 +212,9 @@ export default class ChartAdapterStore {
212
212
}
213
213
214
214
window . flutterChartElement ?. addEventListener ( 'wheel' , this . onWheel , { capture : true } ) ;
215
- window . addEventListener ( 'touchstart' , this . onTouch , { capture : true } ) ;
216
- window . addEventListener ( 'touchmove' , this . onTouch , { capture : true } ) ;
217
- window . addEventListener ( 'touchend' , this . onTouch , { capture : true } ) ;
215
+ window . flutterChartElement ?. addEventListener ( 'touchstart' , this . onTouch , { capture : true } ) ;
216
+ window . flutterChartElement ?. addEventListener ( 'touchmove' , this . onTouch , { capture : true } ) ;
217
+ window . flutterChartElement ?. addEventListener ( 'touchend' , this . onTouch , { capture : true } ) ;
218
218
window . flutterChartElement ?. addEventListener ( 'dblclick' , this . onDoubleClick , { capture : true } ) ;
219
219
window . addEventListener ( 'mousemove' , this . onMouseMove , { capture : true } ) ;
220
220
}
@@ -223,13 +223,13 @@ export default class ChartAdapterStore {
223
223
window . _flutter . initState . isMounted = false ;
224
224
225
225
window . flutterChartElement ?. removeEventListener ( 'wheel' , this . onWheel , { capture : true } ) ;
226
- window . removeEventListener ( 'touchstart' , this . onTouch , { capture : true } ) ;
227
- window . removeEventListener ( 'touchmove' , this . onTouch , { capture : true } ) ;
228
- window . removeEventListener ( 'touchend' , this . onTouch , { capture : true } ) ;
226
+ window . flutterChartElement ?. removeEventListener ( 'touchstart' , this . onTouch , { capture : true } ) ;
227
+ window . flutterChartElement ?. removeEventListener ( 'touchmove' , this . onTouch , { capture : true } ) ;
228
+ window . flutterChartElement ?. removeEventListener ( 'touchend' , this . onTouch , { capture : true } ) ;
229
229
window . flutterChartElement ?. removeEventListener ( 'dblclick' , this . onDoubleClick , { capture : true } ) ;
230
230
window . removeEventListener ( 'mousemove' , this . onMouseMove , { capture : true } ) ;
231
231
clearTimeout ( this . enableVerticalScrollTimer ) ;
232
- clearTimeout ( this . scrollChartParentOnTouchTimer ) ;
232
+ clearTimeout ( this . clearTouchDeltasTimer ) ;
233
233
}
234
234
235
235
onChartLoad ( ) {
@@ -277,8 +277,6 @@ export default class ChartAdapterStore {
277
277
const isForcedScrollArea = x < nonScrollableAreaWidth ;
278
278
279
279
if ( this . touchValues . x && this . touchValues . y ) {
280
- const shouldForceMaxScroll =
281
- Math . abs ( Number ( this . touchValues . deltaYTotal ) ) > 10 && e . type === 'touchend' ;
282
280
const xDiff = this . touchValues . x - pageX ;
283
281
const yDiff = this . touchValues . y - pageY ;
284
282
const deltaXTotal = ( this . touchValues . deltaXTotal ?? 0 ) + xDiff ;
@@ -289,27 +287,35 @@ export default class ChartAdapterStore {
289
287
this . touchValues = { ...this . touchValues , deltaXTotal, deltaYTotal } ;
290
288
291
289
if ( isForcedScrollArea && isVerticalScroll ) {
292
- e . stopImmediatePropagation ( ) ;
290
+ const shouldForceMaxScroll =
291
+ Math . abs ( Number ( this . touchValues . deltaYTotal ) ) > 10 && e . type === 'touchend' ;
292
+ const stopChartPagination = ( ) => {
293
+ // calling _scrollAnimationController.stop() in flutter-chart, value 1 doesn't affect the scale:
294
+ this . flutterChart ?. app . scale ( 1 ) ;
295
+ } ;
293
296
if ( shouldForceMaxScroll ) {
294
- clearTimeout ( this . scrollChartParentOnTouchTimer ) ;
297
+ // handling max scroll on quick swipe
298
+ stopChartPagination ( ) ;
295
299
this . scrollableChartParent ?. scrollTo ( {
296
300
top :
297
301
Number ( this . touchValues . deltaYTotal ) < 0
298
302
? 0
299
303
: this . scrollableChartParent . scrollHeight ,
300
304
behavior : 'smooth' ,
301
305
} ) ;
302
- this . scrollChartParentOnTouchTimer = undefined ;
303
- this . touchValues = { ...this . touchValues , deltaYTotal : 0 , deltaXTotal : 0 } ;
304
- } else if ( ! this . scrollChartParentOnTouchTimer ) {
305
- this . scrollChartParentOnTouchTimer = setTimeout ( ( ) => {
306
- this . scrollableChartParent ?. scrollBy ( {
307
- top : this . touchValues . deltaYTotal ,
308
- behavior : 'smooth' ,
309
- } ) ;
310
- this . scrollChartParentOnTouchTimer = undefined ;
311
- this . touchValues = { ...this . touchValues , deltaYTotal : 0 , deltaXTotal : 0 } ;
312
- } , 150 ) ;
306
+ } else if ( e . type === 'touchmove' ) {
307
+ // handling slow scroll
308
+ stopChartPagination ( ) ;
309
+ this . scrollableChartParent ?. scrollBy ( {
310
+ top : yDiff ,
311
+ } ) ;
312
+ if ( ! this . clearTouchDeltasTimer ) {
313
+ this . clearTouchDeltasTimer = setTimeout ( ( ) => {
314
+ // clearing total deltas to avoid triggering max scroll after the slow scroll
315
+ this . touchValues = { ...this . touchValues , deltaYTotal : 0 , deltaXTotal : 0 } ;
316
+ this . clearTouchDeltasTimer = undefined ;
317
+ } , 100 ) ;
318
+ }
313
319
}
314
320
}
315
321
}
0 commit comments