react-use-gesture

react-use-gesture

需求

  • requestAnimationFrame

使用

import React from 'react'
import { View } from '@tarojs/components'
import { useDrag } from 'react-use-gesture'
import { useGestureConfig } from '@tarojsx/library/dist/react-use-gesture'
const Demo = () => {
const [gestureConfig, containerProps] = useGestureConfig()
const bind = useDrag(({ down, movement: [mx, my], direction: [xDir, yDir], distance, cancel }) => {
console.log('按下', down)
console.log('轴移动距离', mx, my)
console.log('轴移动方向', xDir, yDir)
console.log('直线移动距离', distance)
console.log('取消拖动操作', cancel)
}, gestureConfig)
return <View {...containerProps}>{<View {...bind()} />}</View>
}
03:35Gesture
⬅ 拖拽图片 ➡
参数说明类型默认值
id?容器元素 IDstringuuid
ref?React ref
返回值说明类型
[0]gestureConfig: 传给 react-use-gesture hooks 的配置{}
[1]containerProps: 需要绑定在容器元素上的属性