@@ -15,6 +15,16 @@ class ScrollEnablement extends EventProvider {
15
15
16
16
this . isPhone = isPhone ( ) ;
17
17
18
+ // On Android devices touchmove is thrown one more time than neccessary (together with touchend)
19
+ // so we have to cache the previus coordinates in order to provide correct parameters in the
20
+ // event for Android
21
+ this . cachedValue = { } ;
22
+
23
+ // In components like Carousel you need to know if the user has clicked on something or swiped
24
+ // in order to throw the needed event or not
25
+ this . startX = 0 ;
26
+ this . startY = 0 ;
27
+
18
28
if ( this . isPhone ) {
19
29
containerComponent . addEventListener ( "touchstart" , this . touchStart , { passive : true } ) ;
20
30
containerComponent . addEventListener ( "touchmove" , this . mouseMove , { passive : true } ) ;
@@ -68,6 +78,10 @@ class ScrollEnablement extends EventProvider {
68
78
if ( ! this . isPhone ) {
69
79
document . addEventListener ( "mouseup" , this . mouseUp , { passive : true } ) ;
70
80
document . addEventListener ( "mousemove" , this . mouseMove , { passive : true } ) ;
81
+ } else {
82
+ // Needed only on mobile
83
+ this . startX = touch . pageX ;
84
+ this . startY = touch . pageY ;
71
85
}
72
86
73
87
this . _prevDragX = this . isPhone ? touch . pageX : event . x ;
@@ -94,9 +108,24 @@ class ScrollEnablement extends EventProvider {
94
108
isLeft : dragX > this . _prevDragX ,
95
109
isRight : dragX < this . _prevDragX ,
96
110
} ) ;
111
+
112
+ this . cachedValue . dragX = this . _prevDragX ;
113
+ this . cachedValue . dragY = this . _prevDragY ;
114
+
115
+ this . _prevDragX = dragX ;
116
+ this . _prevDragY = dragY ;
97
117
}
98
118
99
119
ontouchend ( event ) {
120
+ if ( this . isPhone ) {
121
+ const deltaX = Math . abs ( event . changedTouches [ 0 ] . pageX - this . startX ) ;
122
+ const deltaY = Math . abs ( event . changedTouches [ 0 ] . pageY - this . startY ) ;
123
+
124
+ if ( deltaX < 10 && deltaY < 10 ) {
125
+ return ;
126
+ }
127
+ }
128
+
100
129
if ( ! this . _canScroll ) {
101
130
return ;
102
131
}
@@ -108,9 +137,13 @@ class ScrollEnablement extends EventProvider {
108
137
container . scrollLeft += this . _prevDragX - dragX ;
109
138
container . scrollTop += this . _prevDragY - dragY ;
110
139
140
+ const useCachedValues = dragX === this . _prevDragX ;
141
+ const _dragX = useCachedValues ? this . cachedValue . dragX : dragX ;
142
+ // const _dragY = useCachedValues ? this.cachedValue.dragY : dragY; add if needed
143
+
111
144
this . fireEvent ( touchEndEventName , {
112
- isLeft : dragX > this . _prevDragX ,
113
- isRight : dragX < this . _prevDragX ,
145
+ isLeft : _dragX < this . _prevDragX ,
146
+ isRight : _dragX > this . _prevDragX ,
114
147
} ) ;
115
148
116
149
this . _prevDragX = dragX ;
0 commit comments