@@ -19,13 +19,19 @@ export function checkMoveableSnapPoses(
1919 posesY : number [ ] ,
2020 dirXs : string [ ] = [ ] ,
2121 dirYs : string [ ] = [ ] ,
22- customSnapThreshold ?: number ,
22+ customSnapVerticalThreshold : number | undefined ,
23+ customSnapHorizontalThreshold : number | undefined ,
2324) {
2425 const props = moveable . props ;
2526 const snapThresholdMultiples = moveable . state . snapThresholdInfo ?. multiples || [ 1 , 1 ] ;
26- const snapThreshold = selectValue < number > (
27- customSnapThreshold ,
28- props . snapThreshold ,
27+ const snapHorizontalThreshold = selectValue < number > (
28+ customSnapHorizontalThreshold ,
29+ props . snapHorizontalThreshold ,
30+ 5 ,
31+ ) ;
32+ const snapVerticalThreshold = selectValue < number > (
33+ customSnapVerticalThreshold ,
34+ props . snapVerticalThreshold ,
2935 5 ,
3036 ) ;
3137
@@ -35,7 +41,8 @@ export function checkMoveableSnapPoses(
3541 posesY ,
3642 dirXs ,
3743 dirYs ,
38- snapThreshold ,
44+ snapHorizontalThreshold ,
45+ snapVerticalThreshold ,
3946 snapThresholdMultiples ,
4047 ) ;
4148}
@@ -46,12 +53,13 @@ export function checkSnapPoses(
4653 posesY : number [ ] ,
4754 dirXs : string [ ] ,
4855 dirYs : string [ ] ,
49- snapThreshold : number ,
56+ snapHorizontalThreshold : number ,
57+ snapVerticalThreshold : number ,
5058 multiples : number [ ] ,
5159) {
5260 return {
53- vertical : checkSnap ( guidelines , "vertical" , posesX , snapThreshold * multiples [ 0 ] , dirXs ) ,
54- horizontal : checkSnap ( guidelines , "horizontal" , posesY , snapThreshold * multiples [ 1 ] , dirYs ) ,
61+ vertical : checkSnap ( guidelines , "vertical" , posesX , snapVerticalThreshold * multiples [ 0 ] , dirXs ) ,
62+ horizontal : checkSnap ( guidelines , "horizontal" , posesY , snapHorizontalThreshold * multiples [ 1 ] , dirYs ) ,
5563 } ;
5664}
5765export function checkSnapKeepRatio (
@@ -88,7 +96,15 @@ export function checkSnapKeepRatio(
8896 const {
8997 vertical : verticalSnapInfo ,
9098 horizontal : horizontalSnapInfo ,
91- } = checkMoveableSnapPoses ( moveable , dx ? [ endX ] : [ ] , dy ? [ endY ] : [ ] ) ;
99+ } = checkMoveableSnapPoses (
100+ moveable ,
101+ dx ? [ endX ] : [ ] ,
102+ dy ? [ endY ] : [ ] ,
103+ [ ] ,
104+ [ ] ,
105+ undefined ,
106+ undefined ,
107+ ) ;
92108
93109 verticalSnapInfo . posInfos . filter ( ( { pos } ) => {
94110 return isRight ? pos >= startX : pos <= startX ;
@@ -173,7 +189,8 @@ function getStringDirection(dir: number | string) {
173189export function checkSnaps (
174190 moveable : MoveableManagerInterface < SnappableProps , SnappableState > ,
175191 rect : SnapDirectionPoses ,
176- customSnapThreshold ?: number ,
192+ customSnapVerticalThreshold : number | undefined ,
193+ customSnapHorizontalThreshold : number | undefined ,
177194) : { vertical : SnapDirectionInfo ; horizontal : SnapDirectionInfo } {
178195 const poses = splitSnapDirectionPoses ( moveable . props . snapDirections , rect ) ;
179196
@@ -183,7 +200,8 @@ export function checkSnaps(
183200 poses . horizontal ,
184201 poses . verticalNames . map ( name => getStringDirection ( name ) ) ,
185202 poses . horizontalNames . map ( name => getStringDirection ( name ) ) ,
186- customSnapThreshold ,
203+ customSnapVerticalThreshold ,
204+ customSnapHorizontalThreshold ,
187205 ) ;
188206 const horizontalDirection = getStringDirection ( poses . horizontalNames [ result . horizontal . index ] ) ;
189207 const verticalDirection = getStringDirection ( poses . verticalNames [ result . vertical . index ] ) ;
@@ -300,7 +318,8 @@ export function getSnapInfosByDirection(
300318 // pos1 pos2 pos3 pos4
301319 poses : number [ ] [ ] ,
302320 snapDirection : number [ ] ,
303- snapThreshold = 1 ,
321+ customSnapVerticalThreshold : number | undefined ,
322+ customSnapHorizontalThreshold : number | undefined ,
304323) : { vertical : SnapDirectionInfo ; horizontal : SnapDirectionInfo } {
305324 let dirs : number [ ] [ ] = [ ] ;
306325
@@ -357,7 +376,8 @@ export function getSnapInfosByDirection(
357376 xs , ys ,
358377 dirs . map ( dir => getStringDirection ( dir [ 0 ] ) ) ,
359378 dirs . map ( dir => getStringDirection ( dir [ 1 ] ) ) ,
360- snapThreshold
379+ customSnapVerticalThreshold ,
380+ customSnapHorizontalThreshold ,
361381 ) ;
362382 const verticalDirection = getStringDirection ( dirs . map ( dir => dir [ 0 ] ) [ result . vertical . index ] ) ;
363383 const horizontalDirection = getStringDirection ( dirs . map ( dir => dir [ 1 ] ) [ result . horizontal . index ] ) ;
0 commit comments