@@ -103,6 +103,10 @@ export class InnerSlider extends React.Component {
103
103
}
104
104
if ( window . addEventListener ) {
105
105
window . addEventListener ( "resize" , this . onWindowResized ) ;
106
+ window . addEventListener ( "touchstart" , this . touchStart ) ;
107
+ window . addEventListener ( "touchmove" , this . preventTouch , {
108
+ passive : false
109
+ } ) ;
106
110
} else {
107
111
window . attachEvent ( "onresize" , this . onWindowResized ) ;
108
112
}
@@ -120,13 +124,37 @@ export class InnerSlider extends React.Component {
120
124
}
121
125
if ( window . addEventListener ) {
122
126
window . removeEventListener ( "resize" , this . onWindowResized ) ;
127
+ window . removeEventListener ( "touchstart" , this . touchStart ) ;
128
+ window . removeEventListener ( "touchmove" , this . preventTouch , {
129
+ passive : false
130
+ } ) ;
123
131
} else {
124
132
window . detachEvent ( "onresize" , this . onWindowResized ) ;
125
133
}
126
134
if ( this . autoplayTimer ) {
127
135
clearInterval ( this . autoplayTimer ) ;
128
136
}
129
137
} ;
138
+
139
+ touchStart ( e ) {
140
+ this . firstClientX = e . touches [ 0 ] . clientX ;
141
+ this . firstClientY = e . touches [ 0 ] . clientY ;
142
+ }
143
+
144
+ preventTouch ( e ) {
145
+ const minValue = 5 ; // threshold
146
+
147
+ this . clientX = e . touches [ 0 ] . clientX - this . firstClientX ;
148
+ this . clientY = e . touches [ 0 ] . clientY - this . firstClientY ;
149
+
150
+ // Vertical scrolling does not work when you start swiping horizontally.
151
+ if ( Math . abs ( this . clientX ) > minValue ) {
152
+ e . preventDefault ( ) ;
153
+ e . returnValue = false ;
154
+ return false ;
155
+ }
156
+ }
157
+
130
158
UNSAFE_componentWillReceiveProps = nextProps => {
131
159
let spec = {
132
160
listRef : this . list ,
@@ -709,7 +737,7 @@ export class InnerSlider extends React.Component {
709
737
let innerSliderProps = {
710
738
className : className ,
711
739
dir : "ltr" ,
712
- style :this . props . style
740
+ style : this . props . style
713
741
} ;
714
742
715
743
if ( this . props . unslick ) {
0 commit comments