[Android] Wrong user's tap area in overlay #7786
Open
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.
Hi!
I use:
"react-native": "0.72.4",
"react-native-navigation": "^7.37.0",
I faced an annoying problem with
overlays
onAndroid
. I show an overlay with a not full-screen view withinterceptTouchOutside: false
. For example, this view is{x: 0, y: 500, width: 100, height: 100}
When the user tries to tap the overlay the app receives a tap through the overlay (under it). Also, when the user tries to tap an area
{x: 0, y: 0, width: 100, height: 100}
through overlay (usinginterceptTouchOutside: false
) it is blocked for taps.It works well on iOS. Also, it worked well on older versions of react-native and react-native-navigation.
I found a problem in
react-native-navigation/lib/android/app/src/main/java/com/reactnativenavigation/utils/MotionEvent.kt
When we use the old version of the code our not full-screen overlay view performs
getHitRect
in the full-screen parent, so it works correctly.However, when we started to use the new version of the code, we had an issue. It happens cause we use a child of this view from
getChildAt
instead of the original view for thegetHitRect
method.Android View getHitRect
The documentation says that
getHitRect - Hit rectangle in parent's coordinates
.Therefore, when we use the original view for
getHitRect
, it calculates the hit for his full-screen parent, but when we use a view's child, it calculates the hit for the original view as a parent.So, when the user taps on
{x: 50, y: 550}
coordinates on the screen, it will be just{x:50, y:50}
in the not full-screen parent, and the blocking tap area for overlay will be translated to the top of the screen in the wrong place.Additional changes: typo in
REACT_NATVE_VERSION_MINOR
I prepared changes to fix this issue. Let's review and apply ones.