fix(android): release scroll gestures the input cannot consume - #731
Open
lukasz-patalan wants to merge 1 commit into
Open
fix(android): release scroll gestures the input cannot consume#731lukasz-patalan wants to merge 1 commit into
lukasz-patalan wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Android touch/scroll handling in EnrichedTextInputView so vertical drags that the editor can’t consume (because it’s not scrollable or is at a content boundary) can be handled by an enclosing scroll container (e.g., ScrollView), instead of being swallowed by the editor.
Changes:
- Restore content-aware scrollability by making
canScrollVertically/canScrollHorizontallydepend on bothscrollEnabledandsuper’s scroll range. - Track the initial touch position and use
ViewConfigurationtouch slop to avoid changing tap/selection behavior while still enabling gesture handoff for real drags. - Add logic intended to release parent interception when a vertical drag can’t be consumed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
334
to
338
| ) { | ||
| // We cannot scroll, let parent views take care of these touches. | ||
| this.parent.requestDisallowInterceptTouchEvent(false) | ||
| } | ||
| detectScrollMovement = false |
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.
Summary
The problem: on Android, an
EnrichedTextInputplaced inside a scrollable screen always claims vertical drags that start inside it, even when it has no remaining scroll range. As a result, the surroundingScrollViewnever receives those gestures, making the screen feel frozen whenever the drag starts over the editor.What this PR does: the editor keeps handling drags while it can still scroll, and releases them to its parent as soon as it reaches the content boundary.
Why it happens
onTouchEventalready contains the correct logic to release gestures when the editor cannot scroll in any direction:This check comes directly from React Native's
ReactEditText(linked in the comment aboveonTouchEvent). There it works becausecanScrollVertically()andcanScrollHorizontally()come fromTextView, which report whether there is actually more content to scroll.This library overrides both methods to return only the
scrollEnabledflag. With the defaultscrollEnabled={true}, the condition above is therefore never satisfied, so the parent never regains the gesture.scrollEnabled={false}already behaves correctly today because both methods returnfalse.Implementation
canScrollVertically()andcanScrollHorizontally()now returnscrollEnabled && super.canScroll..., restoring the original content-aware behaviour.onTouchEventrecords the touch origin and waits until the pointer moves beyondViewConfiguration.getScaledTouchSlop()before deciding who owns the gesture. This keeps taps, long presses and text selection unchanged.false, allowing the parentScrollViewto continue the same gesture.detectScrollMovementis reset onACTION_UPandACTION_CANCEL, preventing the decision from leaking into subsequent gestures.Behaviour
scrollEnabled={true}, content fitsscrollEnabled={true}, content overflows, drag mid-contentscrollEnabled={true}, content overflows, drag at top/bottom edgescrollEnabled={false}No public API changes are introduced. The only behavioural change is that, with the default
scrollEnabled={true}, vertical drags the editor cannot consume are now passed to the parent instead of being swallowed.Use case
We recently moved our WYSIWYG editor from a dedicated full-screen view into regular forms, where it sits inside a parent
ScrollViewas one field among many. Two things pushed us towards this patch, both coming from the input holding on to touches it cannot use:super.onTouchEventand consumes it as a caret move.Test Plan
Reproduce in the example app's Test screen (the editor is already inside a
ScrollView).Before this change, with content short enough not to overflow the editor, dragging vertically over the editor does not scroll the parent.
After this change:
ScrollViewscrolls.Maxsize mode), drag mid-content: the editor scrolls exactly as before.scrollEnabled={false}, taps, long presses and text selection remain unchanged.Verified locally on an Android emulator (
Pixel9, API 36, arm64).Both
scrolling_after_typingandscrolling_set_valuepass.Compatibility
We could not reproduce this issue on iOS.
UITextViewis backed byUIScrollView, whose gesture handling already appears to behave correctly in this scenario.Checklist