tongyy / react-native-draggable

Draggable Item
MIT License
312 stars 89 forks source link

Draggable with Grid #97

Open Crashtor opened 3 years ago

Crashtor commented 3 years ago

To add grid or grid-like snap functionality I made a modification to the Draggable.js

in the handleOnDrag on line 124 I added

const changeX = clamp(
     Math.round(dx /25) * 25,
     ...
)

and

const changeY = clamp(
     Math.round(dy / 25) * 25,
     ...
)

(Values can be changed depending on grid-size, 25 being a 25px grid)

Although the behavior is as expected, it feels a bit too "snappy" — Any suggestions on how I could modify it to transition to each new grid slot instead of instantly snap to each new grid slot?

Thanks