fix(bottomsheet:android): forward touch-behind events with raw coordi…#484
Open
Siergiej29 wants to merge 1 commit into
Open
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.
Summary
This PR fixes Android touch forwarding when
canTouchBehindis enabled in@nativescript-community/ui-material-bottomsheet.When a bottom sheet is used as a transparent overlay above an interactive screen, touches passed through to the underlying Activity can be dispatched with incorrect coordinates. The visible UI remains in the correct position, but the actual touch targets behind the sheet can be shifted downward.
The fix creates a copied
MotionEvent, updates it to use raw screen coordinates, dispatches that copied event to the Activity, and recycles it in afinallyblock.Problem
I am using a bottom sheet as an overlay on top of an interactive map screen.
The intended behavior is:
The current configuration is:
On Android, the UI behind the sheet is rendered in the correct place, but the touch target appears to be shifted downward. For example, map controls or test buttons are visible in one position, but they only react when tapping below them.
Root Cause
The current Android implementation forwards the original MotionEvent directly to the Activity:
fragment.getActivity().dispatchTouchEvent(event);This is fragile because the event originates from the bottom sheet/dialog overlay window, while the Activity/root view may interpret the event in a different coordinate space.
That matches the observed behavior: the underlying UI is visually correct, but hit testing happens with shifted coordinates.
Fix
Instead of forwarding the original event directly, this PR copies the event, updates its coordinates to raw screen coordinates, dispatches the copied event, and recycles it safely:
Using try/finally ensures the copied MotionEvent is recycled even if dispatching throws.
Reproduction
A minimal reproduction project is available here:
The reproduction includes:
Steps:
Notes
The README currently mentions that canTouchBehind works properly when dismissOnBackgroundTap is set to true.
This issue specifically affects the use case where the sheet should stay open while interacting with the content behind it, so the configuration uses:
dismissOnBackgroundTap: falseEven if this combination is considered a special case, forwarding a copied event with screen coordinates is safer than dispatching the original overlay event directly.
Testing
Tested locally in a NativeScript app on Android with:
The underlying controls receive touches at the expected visible position after applying this change.