@@ -142,6 +142,21 @@ function getVelocityDirectionClamp(event: PanGestureHandlerEventExtra, direction
142
142
return { x, y} ;
143
143
}
144
144
145
+ function checkThresholds ( event : PanGestureHandlerEventExtra ,
146
+ directions : PanningDirections [ ] ,
147
+ velocity : number ,
148
+ threshold : Required < PanDismissThreshold > ) {
149
+ const velocityPassedThreshold = velocity > threshold . velocity ;
150
+ const xPassedThreshold =
151
+ ( directions . includes ( PanningDirections . RIGHT ) && event . translationX > threshold . x ) ||
152
+ ( directions . includes ( PanningDirections . LEFT ) && - event . translationX > threshold . x ) ;
153
+ const yPassedThreshold =
154
+ ( directions . includes ( PanningDirections . DOWN ) && event . translationY > threshold . y ) ||
155
+ ( directions . includes ( PanningDirections . UP ) && - event . translationY > threshold . y ) ;
156
+
157
+ return { velocityPassedThreshold, xPassedThreshold, yPassedThreshold} ;
158
+ }
159
+
145
160
/**
146
161
* Will return undefined if should not dismiss
147
162
*/
@@ -157,15 +172,12 @@ export function getDismissVelocity(event: PanGestureHandlerEventExtra,
157
172
x : threshold ?. x || DEFAULT_THRESHOLD . x ,
158
173
y : threshold ?. y || DEFAULT_THRESHOLD . y
159
174
} ;
160
- const allowedVelocity = getVelocityDirectionClamp ( event , directions ) ;
161
- const velocity = Math . sqrt ( Math . pow ( allowedVelocity . x , 2 ) + Math . pow ( allowedVelocity . y , 2 ) ) ;
162
- const velocityPassedThreshold = velocity > _threshold . velocity ;
163
- const xPassedThreshold =
164
- ( directions . includes ( PanningDirections . RIGHT ) && event . translationX > _threshold . x ) ||
165
- ( directions . includes ( PanningDirections . LEFT ) && - event . translationX > _threshold . x ) ;
166
- const yPassedThreshold =
167
- ( directions . includes ( PanningDirections . DOWN ) && event . translationY > _threshold . y ) ||
168
- ( directions . includes ( PanningDirections . UP ) && - event . translationY > _threshold . y ) ;
175
+ const clampedVelocity = getVelocityDirectionClamp ( event , directions ) ;
176
+ const velocity = Math . sqrt ( Math . pow ( clampedVelocity . x , 2 ) + Math . pow ( clampedVelocity . y , 2 ) ) ;
177
+ const { velocityPassedThreshold, xPassedThreshold, yPassedThreshold} = checkThresholds ( event ,
178
+ directions ,
179
+ velocity ,
180
+ _threshold ) ;
169
181
if ( velocityPassedThreshold || xPassedThreshold || yPassedThreshold ) {
170
182
let velocity : Partial < Frame > = { } ;
171
183
if ( velocityPassedThreshold ) {
0 commit comments