Add DragGesture and onLongPressGesture - #50
Merged
Conversation
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.
Adds continuous gestures:
DragGesture()with.onChanged/.onEndedapplied via.gesture(_:), and.onLongPressGesture(perform:).Keeping the bridge O(1)
A drag needs two numbers per event, but the JNI surface is a fixed set of single-value entry points and growing it is the fragile part of this architecture. So the interpreter encodes
"<phase>;<startX>,<startY>;<x>,<y>"(in points) through the existing string callback and Swift rebuilds aDragGesture.Valuefrom it — no new bridge entry point.Two real bugs the on-device pass caught
Both were invisible to unit tests and only showed up dragging a real box:
Offset: 1, 1for a 150px drag). Fixed by accumulating per-event deltas instead of reading absolute positions.onChangedwrites state → re-evaluation → a fresh callback id.pointerInputwas keyed on that id, so the detector — a long-running coroutine — was cancelled and restarted on the first event, andonEndednever fired. Fixed by keying on the node's stable id and reading the current callback id from a holder, so it never dispatches to a reclaimed callback. (Same generation-scoped-id hazard as the search field and.taskcancellation.)Tap and long press also share a single
combinedClickabledetector rather than two competing pointer handlers, which would fight over the gesture.Verification
swift test— 3 new tests (long press callback distinct from tap; drag payload → translation for changed/ended; malformed payload ignored), 74 total passingOffset: 45, 30dp andLast drop: 45, 30. The shortfall from the raw 55×36 dp is Compose's touch slop consumed before recognition; the 1.5 ratio is preserved exactly, andonEndedreports the same final translation.Taps: 1, Long presses: 0; a ~900 ms hold then gaveTaps: 1, Long presses: 1— each fires only its own handler.Scope
.gesture(_:)acceptsDragGesture(aGesturemarker protocol is in place for future types). Magnification/rotation and gesture composition (.sequenced,.simultaneously) are not included.