What is the alternative for `dragGestureFilter` wi...
# compose
t
What is the alternative for
dragGestureFilter
with
startDragImmediately = true
since it was deprecated?
I tried using
pointerInput
with
detectDragGestures
but that seems to only activate after a touch slop. I would like to disable the touch slop just like before so the lambda is called immediately when view is touched.
I am using this for a (round) color picker. When the user touches the colour picker somewhere, the new location (color) should immediately be detected. And when swiping in any direction new colors should be detected.
This is essentially two steps: 1) wait for down event, 2) start getting drag callbacks on the pointer id that you get from the down event. 🙂
👍 2
t
Thanks a lot for the information, I have it working now. It looks like this:
Copy code
.pointerInput(Unit) {
    fun updateColor(position: Offset) {
        TODO()
    }
    forEachGesture {
        awaitPointerEventScope {
            val down = awaitFirstDown(requireUnconsumed = false)
            updateColor(down.position)
            down.consumeAllChanges()
            drag(down.id) { change ->
                updateColor(change.position)
                change.consumeAllChanges()
            }
        }
    }
}
Does this look alright? I am not sure whether to consume the
down
event. The sample does not do that, but I am using the
down
position here.
g
Consuming the down event prevents it from being read by other gesture detectors. If you don't have to worry about gesture disambiguation, then consuming the down is a good idea. If you had a button under it, you would see the ripple on the press if you didn't consume the down. Most gesture detectors have to worry about disambiguation and don't consume the down because they aren't sure if they will be the one acting. You're doing it right. When you consume a pointer input, you're essentially telling all the other gesture detectors, "Hands off, this gesture is mine."
I should clarify what I said above. Consuming doesn't prevent detectors from reading the pointer input, but well-behaved gesture detectors will not act on a consumed gesture except to bow out.
👍 1
t
I understand now, thanks for the very detailed explanation, George.
👍 1