[BUG] modifyTarget is causing a jumpy transition
2. Describe the bug
Using modifyTarget on a Draggable's element dragTransition is resulting in a jumpy behavior, this is happening on drag end where it seems like the element is skipping a bit ahead!
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
https://codesandbox.io/s/polished-waterfall-u037u?file=/src/App.js
5. Expected behavior
a smooth page transition like animation like the one available to use in Framer
6. Video or screenshots
here is a video that shows how it is behaving: https://res.cloudinary.com/elia-d/video/upload/v1590566454/Screen_Recording_2020-05-27_at_09.49.06.mov
It's possible to use animation controls and the onDragTransitionEnd callback to create snap points. The only caveat is that snapping happens after inertia, so make sure to set the timeConstant of the dragTransition low enough.
import { snap } from '@popmotion/popcorn';
import { motion, useAnimation, useMotionValue } from 'framer-motion';
function DraggablePanel() {
const controls = useAnimation();
const x = useMotionValue(0);
return (
<motion.div
style={{ x, width: panelWidth }}
animate={controls}
drag="x"
dragTransition={{
min: -contentWidth,
max: 0,
timeConstant: 100,
power: 0.4
}}
onDragTransitionEnd={() => {
const snapDistance = 100;
const snapTo = snap(snapDistance);
controls.start({
x: snapTo(x.get()),
transition: { type: "spring", stiffness: 300, damping: 200 }
});
}}
>
...
</motion.div>
);
}
This could be fixed with an update of the Popmotion dependency. I've experimented with a couple of ways to remove any potential blocks of that update. First, #596 was to make possible a switch to Popmotion ^8.7.3 without bundle size increases. Second, a candidate beta-9 branch of Popmotion which includes the inertia changes that would fix this issue.
Some considerations:
- As far as bundle size goes, merging #596 and using 8.7.3 would be lighter than an update to a published version of the beta-9 candidate without build changes.
- Updating the beta adds the benefit of removing some side-effects that are adding unused mouse/touch listeners in framer-motion.