Created
July 13, 2020 21:21
-
-
Save BetterProgramming/9a8fcb523c6cc86d9d1f2fa2186dd595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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