Skip to content

Commit

Permalink
Fix drag-and-drop start gesture to only use long-press with touch, an…
Browse files Browse the repository at this point in the history
…d also to use drag-start with mouse.
  • Loading branch information
m-sasha committed Oct 14, 2024
1 parent 724a036 commit df2d1c6
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,43 @@

package androidx.compose.foundation.draganddrop

import androidx.compose.foundation.PointerMatcher
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.runtime.Immutable
import androidx.compose.ui.draw.CacheDrawScope
import androidx.compose.ui.draw.DrawResult
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.asComposeCanvas
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.draw
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.input.pointer.PointerButton
import androidx.compose.ui.input.pointer.PointerInputScope
import org.jetbrains.skia.Picture
import org.jetbrains.skia.PictureRecorder
import org.jetbrains.skia.Rect

@Immutable
internal actual object DragAndDropSourceDefaults {
actual val DefaultStartDetector: DragAndDropStartDetector = {
detectTapGestures(onLongPress = { offset -> requestDragAndDropTransfer(offset) })
detectDragStart(::requestDragAndDropTransfer)
}
}

private suspend fun PointerInputScope.detectDragStart(onDragStart: (Offset) -> Unit) {
detectDragGestures(
matcher = PointerMatcher.mouse(PointerButton.Primary),
onDragStart = onDragStart,
onDrag = { _ -> }
)
detectTapGestures(
matcher = PointerMatcher.touch,
onLongPress = onDragStart
)
}

internal actual class CacheDrawScopeDragShadowCallback {
private var cachedPicture: Picture? = null

Expand Down

0 comments on commit df2d1c6

Please sign in to comment.