dav*_*ler 2 javascript draggable reactjs react-spring react-use-gesture
文档中的拖动示例(例如此示例)速度非常快,并且非常准确地映射到我的手指位置。我尝试一对一复制示例,但与我的手指位置相比有明显的滞后。
这是一个代码沙箱示例,在真实设备上测试时有明显的滞后。
信息:
"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"
Run Code Online (Sandbox Code Playgroud)
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>
);
}
Run Code Online (Sandbox Code Playgroud)
我梳理了示例的源代码。事实上,问题出在反应弹簧上,我需要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>
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1561 次 |
| 最近记录: |