Add moveTo() for continuing an active gesture#2
Open
comp615 wants to merge 1 commit into
Open
Conversation
draw() owns the per-frame easing loop but guards itself with require(ongoingGesture == null), so there's no public way to animate an already-down pointer. This blocks composing multi-phase gestures such as long-press → drag → hold → drag → release, where every phase must be one continuous pointer stream. Add a moveTo(position, duration, pointerId) primitive that animates [pointerId] from its current position to [position] using the same EaseInOutSine + frame-clock + historical-position machinery as draw(). It dispatches only ACTION_MOVE events — callers are responsible for the surrounding down()/up(). Implementation extracts draw()'s inner per-frame loop into a private animateAlongPaths() helper. draw() now calls it after its own down(), and moveTo() calls it with the existing ongoingGesture.downTime. No behaviour change for existing callers — all 7 existing Paparazzi snapshots are still byte-identical. Closes saket#1 Amp-Thread-ID: https://ampcode.com/threads/T-019e8e27-d50b-77b8-af50-adf21074e1f4 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1.
Summary
Adds a
moveTo(position, duration, pointerId = PointerId(0))primitive toTouchRobotGestureScopethat animates an already-down pointer to a new position over a duration, dispatching onlyACTION_MOVEevents. This is the building block for composable multi-phase gestures (long-press → drag → hold → drag → release) where every phase must be one continuous pointer stream.touchRobot.onRoot().performGesture { down(start) delay(viewConfiguration.longPressTimeoutMillis + 100.milliseconds) moveTo(dwell, 700.milliseconds) delay(5.seconds) // ← stationary hold moveTo(drop, 700.milliseconds) up() }Scope decision: just
moveTo, not all four primitives from #1In the issue I proposed
press/longPress/moveTo/hold. On re-reading the source I think onlymoveTois actually missing — the other three are trivial compositions of API that's already public:press(pos, dur)down(pos); delay(dur)longPress(pos)down(pos); delay(viewConfiguration.longPressTimeoutMillis + 100.milliseconds)hold(dur)delay(dur)(literally identical — no event dispatch)Whereas
moveTohas no public equivalent — the per-frame easing loop lives insidedraw()and is guarded byrequire(ongoingGesture == null). So this PR ships just the primitive that has no workaround. Happy to follow up with the sugar in a separate PR if you'd like it — easier to add than to remove from a fresh 0.1.0 API surface.Implementation
draw()'s inner per-frame loop is extracted into a privateanimateAlongPaths()helper. Bothdraw()andmoveTo()call it;draw()keeps owning its owndown()/up()and contour iteration, whilemoveTo()reuses the existingongoingGesture.downTimeand a one-linePathfrom current → target position.The helper takes two times to disambiguate them —
motionDownTimefor theMotionEvent.downTimefield,motionStartTimefor animation progress. They coincide fordraw()(down + animate happen in the same tick) but differ formoveTo()(down happened earlier, possibly with a long hold in between).Verification
./gradlew checkwith noMon existing snapshot files.)move to continues active pointerrecords a 4-second animation ofdown → wait (long-press) → moveTo → hold → moveTo → upagainst apointerInput { … awaitPointerEvent() }consumer. The overlay text readsdown=1 up=0for the entire animation, proving the gesture stays continuous across themoveTo/delaychain.API additions
🤖 Drafted with AI assistance.