小编Ulf*_*son的帖子

结合 detectorTapGestures 和 detectorDragGesturesAfterLongPress?

我们需要能够在长按 Jetpack Compose 中的同一组件后检测到点击和拖动手势。

要检测点击,我们可以这样做:

Modifier.pointerInput(graphData) {
    detectTapGestures(
        ...
    )
}
Run Code Online (Sandbox Code Playgroud)

并检测长按后的拖动手势:

Modifier.pointerInput(graphData) {
    detectDragGesturesAfterLongPress(
        ...
    )
}
Run Code Online (Sandbox Code Playgroud)

但不可能同时使用两者,因为第一个detect*将消耗指针事件:

Modifier.pointerInput(graphData) {
    detectTapGestures(
        ...
    )
    detectDragGesturesAfterLongPress(
        ...
    )
}
Run Code Online (Sandbox Code Playgroud)

是否有可能以更方便的方式实现这一点,然后滚动我们自己的自定义函数来复制 detectorDragGesturesAfterLongPress 中的大部分代码?

android kotlin android-jetpack-compose android-jetpack-compose-gesture

11
推荐指数
1
解决办法
2169
查看次数