Repository navigation
fix(android): a long-press on a link no longer also opens selection or block menus - #1011
Merged
hryhoriiK97 merged 2 commits intoOct 18, 2026
Conversation
…r block menus TextView posts its own long-press callback in View.onTouchEvent before LinkLongPressMovementMethod sees ACTION_DOWN, and the link long-press runnable uses the same timeout. The runnable cancelled the view's long-press, but only when it happened to run first. When the view's callback ran first, a long-press on a link opened the link long-press and also text selection (paragraphs) or the block context menu (table cells). Cancel the view's long-press when the press lands on a link, before scheduling the link long-press. A long-press on plain text is unchanged.
voida6
force-pushed
the
fix/android-link-long-press-race
branch
from
October 16, 2026 03:44
d83e248 to
52852f5
Compare
Contributor
Author
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hryhoriiK97
approved these changes
Oct 18, 2026
Collaborator
|
Thanks for the fix and the detailed write-up! I reproduced the race on an Android emulator: the link long-press sometimes also opened text selection or the table menu without the patch, and only the link fired with it. I pushed a small cleanup on top:
|
Contributor
Author
|
Thanks! |
1 of 6 tasks
Contributor
Author
|
Thanks! |
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.
What/Why?
On Android, a long-press on a link sometimes opens two things at once: the link long-press (
onLinkLongPress, which apps use for a link menu) and the view's own long-press. In a paragraph that second one is text selection with its toolbar; in a table cell it is the table's Copy / Copy as Markdown menu.It is a race between two callbacks with the same timeout:
TextView.onTouchEventcallsView.onTouchEventfirst, which posts the view's long-press callback (ViewConfiguration.getLongPressTimeout()).ACTION_DOWN.LinkLongPressMovementMethod.scheduleLongPressposts the link runnable with the same timeout.widget.cancelLongPress(), but that only helps when it runs first. When the view's callback runs first, both fire.I logged both callbacks on a Galaxy S25 Ultra (Android 16) in an app using
react-native-enriched-markdown. Before this change, the view'sperformLongClickran 1-11 ms before the link runnable in 2 of 3 long-presses on a table link and in every long-press on a paragraph link. Those were the presses that opened two menus.The fix calls
widget.cancelLongPress()inscheduleLongPress, which only runs for anACTION_DOWNon a link, so the view's long-press never fires for that gesture.cancelLongPress()also removes the pending tap callback that posts the long-press later inside scrolling containers, and the framework only re-arms a long-press for ambiguous or deep presses while one is still pending. A long-press on plain text is unchanged. The same 4 lines go into both Android implementations (react-native-enriched-markdownandenriched-markdown-android/ui).Testing
LinkLongPressInteractionTest(Robolectric,enriched-markdown-android/ui) dispatches a real long-press through an attachedEnrichedMarkdownInternalTextwith a long-click listener. Onmain, a long-press on a link fires both the link long-press and the view's long-click and the test fails; with the fix only the link long-press fires. A second test checks that a long-press on plain text still reaches the view../gradlew :ui:testDebugUnitTestfor the new test and:ui:ktlintCheckpass.react-native-enriched-markdownwith this patch, on a Galaxy S25 Ultra (Android 16, One UI). Same table and paragraph links as before.Recordings (white dots are touches). Before:
before-double-menus.mp4
After:
after-single-menu.mp4
PR Checklist
iOS is unchanged. I verified in a downstream app (T3 Code) instead of the example app, and did not run the Maestro suite. No docs change: link long-press behavior is unchanged except that it no longer collides with the view's own long-press.