在文档中拖动示例(如这一个 )非常快,并且非常准确地映射到我的手指位置。我试过一对一地复制这些例子,但要赶上我的手指位置显然有一个滞后。
下面是一个代码沙箱示例在实际设备上测试时有明显的滞后。
信息:
"react": "17.0.2",
"react-dom": "17.0.2",
"react-scripts": "4.0.0",
"react-spring": "9.1.2",
"react-use-gesture": "9.1.3"function PullRelease() {
const [{ x }, api] = useSpring(() => ({ x: 0 }));
const bind = useDrag(({ movement: [mx], down }) =>
api.start({ x: down ? mx : 0 })
);
return (
<animated.div {...bind()} style={{ padding: 40, background: "gold", x }}>
Hello World
</animated.div>
);
}发布于 2021-05-25 16:46:02
我梳理了一下示例的源代码。事实上,问题是反应-弹簧,我需要提供immediate: true,而触摸是活跃的。
https://codesandbox.io/s/react-spring-gesture-basic-swipe-immediate-6bje9?file=/src/App.js
function PullRelease() {
const [{ x }, api] = useSpring(() => ({ x: 0 }));
const bind = useDrag(({ movement: [mx], down }) =>
api.start({ x: down ? mx : 0,
immediate: down // the key line
})
);
return (
<animated.div {...bind()} style={{ padding: 40, background: "gold", x }}>
Hello World
</animated.div>
);
}https://stackoverflow.com/questions/67691501
复制相似问题