Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created July 13, 2020 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/9a8fcb523c6cc86d9d1f2fa2186dd595 to your computer and use it in GitHub Desktop.
Save BetterProgramming/9a8fcb523c6cc86d9d1f2fa2186dd595 to your computer and use it in GitHub Desktop.
const bind = useDrag(
({ down, tap, movement: [x] }) => {
// Tap handler
if (!down && tap) {
set({ x: toggled ? -RANGE : 0 });
setToggled(!toggled);
return;
}
// Drag handler
if (down) {
set({ x });
} else {
const isToggled = x > -RANGE / 2;
set({ x: isToggled ? 0 : -RANGE });
setToggled(isToggled);
}
},
{
initial: () => [x.get(), 0],
bounds: { left: -RANGE, right: 0, top: 0, bottom: 0 },
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment