@@ -70,10 +70,10 @@ export const getClientScroll = (
70
70
} = prevScrollState ;
71
71
72
72
nextScrollState . isScrollingLeft = isScrollingLeft ( x , nextScrollState ) ;
73
- nextScrollState . isScrollingRight = ! nextScrollState . isScrollingLeft ;
73
+ nextScrollState . isScrollingRight = isScrollingRight ( x , nextScrollState ) ;
74
74
75
75
nextScrollState . isScrollingUp = isScrollingUp ( y , nextScrollState ) ;
76
- nextScrollState . isScrollingDown = ! nextScrollState . isScrollingUp ;
76
+ nextScrollState . isScrollingDown = isScrollingDown ( y , nextScrollState ) ;
77
77
78
78
nextScrollState . xTurn =
79
79
nextScrollState . isScrollingLeft === prevIsScrollingLeft ? prevXTurn : x ;
@@ -102,6 +102,19 @@ const isScrollingLeft = (x: number, prev: IScroll) => {
102
102
}
103
103
} ;
104
104
105
+ const isScrollingRight = ( x : number , prev : IScroll ) => {
106
+ switch ( true ) {
107
+ case x > prev . x :
108
+ return true ;
109
+ case x < prev . x :
110
+ return false ;
111
+ case x === prev . x :
112
+ return prev . isScrollingRight ;
113
+ default :
114
+ throw new Error ( 'Could not calculate isScrollingRight' ) ;
115
+ }
116
+ } ;
117
+
105
118
const isScrollingUp = ( y : number , prev : IScroll ) => {
106
119
switch ( true ) {
107
120
case y < prev . y :
@@ -111,7 +124,20 @@ const isScrollingUp = (y: number, prev: IScroll) => {
111
124
case y === prev . y :
112
125
return prev . isScrollingUp ;
113
126
default :
114
- throw new Error ( 'Could not calculate yDir' ) ;
127
+ throw new Error ( 'Could not calculate isScrollingUp' ) ;
128
+ }
129
+ } ;
130
+
131
+ const isScrollingDown = ( y : number , prev : IScroll ) => {
132
+ switch ( true ) {
133
+ case y > prev . y :
134
+ return true ;
135
+ case y < prev . y :
136
+ return false ;
137
+ case y === prev . y :
138
+ return prev . isScrollingDown ;
139
+ default :
140
+ throw new Error ( 'Could not calculate isScrollingDown' ) ;
115
141
}
116
142
} ;
117
143
0 commit comments