Skip to content

fix(android): keep a zoomed scroll view still as fingers land and lift - #2301

Merged
houko merged 2 commits into
nsgo-dev:mainfrom
XiaoMengXinX:fix-android-zoom-pinch-lift
Nov 26, 2026
Merged

houko merged 2 commits into
nsgo-dev:mainfrom
XiaoMengXinX:fix-android-zoom-pinch-lift

Conversation

@XiaoMengXinX

@XiaoMengXinX XiaoMengXinX commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A zoomable Scroll on Android pans by the middle of the fingers while they pinch, but it took that middle from the wrong fingers when their number changed, so the content jumped by about half the fingers' spread:

  • A second finger landing: onInterceptTouchEvent takes the touch at ACTION_POINTER_DOWN, so onTouchEvent never sees that event and the pan's anchor stays on the first finger. The next move then measures from the two fingers' middle.
  • One of two fingers lifting: at ACTION_POINTER_UP the lifting finger is still in the event, so the anchor became the middle of both fingers. The next move measures from the one finger that stays.

The scroll view now takes its anchor from the middle of the fingers that remain down, both when it intercepts a second finger and when one lifts.

In an app with a pinch-zoomable picture viewer, every pinch ended with the picture jumping by 100 to 200 points. The app's logs of the scroll view's offset showed the jump in a single frame, with the zoom scale unchanged and no pan events.

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

iOS pans a zoomed UIScrollView itself and does not have this jump.

Screenshots

None. The change is in how the content moves during a pinch, which a still image does not show.

Verification

Run on this branch rebased onto main at 9f2ee7e:

  • go tool nsgo check -target android ./internal/platform/android
  • go tool nsgo test ./internal/platform/android -- -count=1: 154 passed, 9 skipped.
  • go tool nsgo test -target android: not run.

The test stub's MotionEvent now takes several fingers and an action index. ZoomScrollCheck gains a case that pans with two fingers, lifts one, and checks that the content stays put and then follows the remaining finger. Against main's Scrolling.java the case fails with two fingers did not pan by their middle: -50,40; with this change it passes.

I ran the app built with a runtime from this Scrolling.java on a Pixel 9 (Android 17), using internal/platform/android/runtime/build.sh. One-finger pans and the scroll view's double-tap zoom still work there. I could not script a two-finger pinch on the device, so that part rests on the JVM test. This pull request leaves classes.dex and classes.jar alone, as AGENTS.md asks.

Checklist

  • The title is a Conventional Commit, such as fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and a capability users can see has a line in a changelog.d/ fragment, not in CHANGELOG.md.
  • New third-party code, assets and dependencies name their source and license.

@github-actions

Copy link
Copy Markdown

Thanks for your first pull request! Before it is merged:

  • Write the title as a Conventional Commit, such as fix(linux): ...; a squash merge uses it as the commit subject.
  • Run go tool nsgo check and go tool nsgo test, and say in the description what you ran on which targets and what you could not.
  • Making a change says what a pull request needs, and AGENTS.md and ARCHITECTURE.md how the code is organized.

@github-actions github-actions Bot added bug Something isn't working size/S documentation Improvements or additions to documentation Android labels Nov 24, 2026
@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch from a0fbec2 to d8cec13 Compare November 24, 2026 11:20
@houko houko self-assigned this Nov 25, 2026

@houko houko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against the latest origin/main (8d57260). The pointer-down and pointer-up anchor changes in internal/platform/android/java/dev/oneo/nsgo/Scrolling.java match the described jump, and the added ZoomScrollCheck regression passes locally.

Local verification:

  • go tool nsgo check -target android ./internal/platform/android
  • go tool nsgo test -run '^TestZoomScrollBrakingTouch$' ./internal/platform/android -- -count=1

I cannot approve yet because the pull request is 27 commits behind main and its current GitHub checks contain only triage checks. Please rebase onto current main and publish the repository check/test results before approval.

@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch from d8cec13 to 4d5f231 Compare November 25, 2026 10:01
@XiaoMengXinX

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (28318fe, 0.3.2); the head is now 4d5f231, with no conflicts and no change to the diff.

Results on the rebased commit, run locally on macOS:

  • go tool nsgo check -target android ./internal/platform/android: passed.
  • go tool nsgo test ./internal/platform/android -- -count=1: 154 passed, 0 failed, 9 skipped.

The repository's own Check, Test, Repository quality and CodeQL workflows are queued for this push but wait for a maintainer to approve workflow runs from a first-time contributor, which is why only the triage checks show. Could someone with access approve them?

@houko houko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source-level review against #2302. In Scrolling.ZoomScroll.onInterceptTouchEvent, the ACTION_POINTER_DOWN branch resets lastX/lastY from the new two-finger middle before interception returns, which prevents the first subsequent move from applying the old one-finger anchor. In onTouchEvent, ACTION_POINTER_UP excludes getActionIndex() from the middle before storing the next anchor. The new regression then checks no offset jump on lift and verifies the following one-finger delta. I found no behavioral defect in this change. Approval remains blocked only because the branch is stale and its required checks are not current.

@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch from 4d5f231 to 555e1b2 Compare November 25, 2026 11:51
@XiaoMengXinX

Copy link
Copy Markdown
Contributor Author

Rebased again onto current main (7cf20b5); the head is now 555e1b2, with no conflicts and the same diff.

On that commit, locally on macOS:

  • go tool nsgo check -target android ./internal/platform/android: passed.
  • go tool nsgo test ./internal/platform/android -- -count=1: 154 passed, 0 failed, 9 skipped.

main gained 24 commits in the two hours since the previous rebase, so the branch will fall behind again soon. The Check, Test, Repository quality and CodeQL runs for this push are in action_required: they start only after a maintainer approves workflow runs for a first-time contributor, which I cannot do from the fork. Once they are approved I will follow up on any failure.

@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch from 555e1b2 to 1d775ae Compare November 25, 2026 13:16
@XiaoMengXinX

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (d52cdb5); the head is now 1d775ae, with no conflicts and the same diff.

On that commit, locally on macOS:

  • go tool nsgo check -target android ./internal/platform/android: passed.
  • go tool nsgo test ./internal/platform/android -- -count=1: 154 passed, 0 failed, 9 skipped.

The Check, Test, Repository quality and CodeQL runs for this push still wait for a maintainer to approve workflow runs.

@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch from 1d775ae to a12c6e6 Compare November 25, 2026 13:44
@XiaoMengXinX

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (43b504e); the head is now a12c6e6. No conflicts, and the diff is unchanged: main gained 8 commits since the last rebase and none of them touched internal/platform/android.

Locally on macOS:

  • go tool nsgo check -target android ./internal/platform/android: passed.
  • go tool nsgo test ./internal/platform/android -- -count=1: 154 passed, 0 failed, 9 skipped.

Check, Test, Repository quality and CodeQL for this head are still action_required; they start only after a maintainer approves workflow runs for a first-time contributor.

@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch 2 times, most recently from 2fba468 to fc4b6de Compare November 25, 2026 15:39
@XiaoMengXinX
XiaoMengXinX force-pushed the fix-android-zoom-pinch-lift branch from fc4b6de to 4993e9d Compare November 25, 2026 17:12
@XiaoMengXinX

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (9f2ee7e); the head is now 4993e9d. No conflicts, and the diff is unchanged. Locally on macOS:

  • go tool nsgo check -target android ./internal/platform/android: passed.
  • go tool nsgo test ./internal/platform/android -- -count=1: 154 passed, 0 failed, 9 skipped.

@houko your two reviews left only one blocker: the repository checks are not current. Every push puts Check, Test, Repository quality and CodeQL in action_required, because workflow runs from a first-time contributor wait for a maintainer to approve them, and I cannot approve runs from the fork myself. Could you approve the runs for 4993e9d, or point me to someone who can? I will follow up on any failure once they run.

@houko houko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased onto latest main and verified locally with go tool nsgo check -target android ./internal/platform/android and go tool nsgo test ./internal/platform/android -run '^TestZoomScrollBrakingTouch$' -count=1. The touch-anchor change matches the second-finger landing and finger-lift paths in Scrolling.java, and the targeted regression passes. Approving and enabling merge after required checks.

@houko
houko enabled auto-merge (rebase) November 26, 2026 00:00
@houko
houko merged commit 93d9e57 into nsgo-dev:main Nov 26, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android bug Something isn't working documentation Improvements or additions to documentation size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants