question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android: No way to pass js-touches through the views without "pointerEvents="NONE"

See original GitHub issue

Hi all and thanks for this project!

We are creating this small library to cut the holes inside view and pass clicks through them.

So, we faced that there is no way on Android to pass js-touch events (that needed for all Touchables) through the custom view, using default android’s way

onTouchEvent(event: MotionEvent){
   return false;
}

The one and only click-checking mechanism, that we’ve found located in TouchTargetHelper.java and it uses only view’s bounding (top, bottom, left, right) + hitSlopRect

code:
private static boolean isTransformedTouchPointInView(
      float x, float y, ViewGroup parent, View child, PointF outLocalPoint) {
    float localX = x + parent.getScrollX() - child.getLeft();
    float localY = y + parent.getScrollY() - child.getTop();
    Matrix matrix = child.getMatrix();
    if (!matrix.isIdentity()) {
      float[] localXY = mMatrixTransformCoords;
      localXY[0] = localX;
      localXY[1] = localY;
      Matrix inverseMatrix = mInverseMatrix;
      matrix.invert(inverseMatrix);
      inverseMatrix.mapPoints(localXY);
      localX = localXY[0];
      localY = localXY[1];
    }
    if (child instanceof ReactHitSlopView && ((ReactHitSlopView) child).getHitSlopRect() != null) {
      Rect hitSlopRect = ((ReactHitSlopView) child).getHitSlopRect();
      if ((localX >= -hitSlopRect.left
              && localX < (child.getRight() - child.getLeft()) + hitSlopRect.right)
          && (localY >= -hitSlopRect.top
              && localY < (child.getBottom() - child.getTop()) + hitSlopRect.bottom)) {
        outLocalPoint.set(localX, localY);
        return true;
      }

      return false;
    } else {
      if ((localX >= 0 && localX < (child.getRight() - child.getLeft()))
          && (localY >= 0 && localY < (child.getBottom() - child.getTop()))) {
        outLocalPoint.set(localX, localY);
        return true;
      }

      return false;
    }
  }

So we’d like to write some custom method to check click availability for View.

Something like

interceptsTouchEvent(touchX: Float, touchY: Float): Boolean

for ReactViewGroup What do you guys think about it?

Description

Violet view - custom android’s view (inherited from ReactViewGroup) with

onTouchEvent(event: MotionEvent){
   return false;
}

So it’s passes all native touches to scroll view, but don’t do it with TouchableOpacity

out

React Native version:

System: OS: macOS 10.15.4 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Memory: 195.21 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node Yarn: 1.22.4 - ~/.yarn/bin/yarn npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.9.1 - /Users/stepankopylov/.rvm/rubies/ruby-2.6.3/bin/pod SDKs: iOS SDK: Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: API Levels: 23, 28, 29 Build Tools: 28.0.3, 29.0.2, 30.0.0 System Images: android-29 | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 3.6 AI-192.7142.36.36.6392135 Xcode: 11.5/11E608c - /usr/bin/xcodebuild Languages: Java: 1.8.0_222 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.2 => 0.62.2 npmGlobalPackages: react-native: Not Found

Steps To Reproduce

Create native android module with view that passes all touches through Cover all the screen with it, put some Touchables under, and try to click

Expected Results

Passing clicks to Touchables under

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

4reactions
stephenkopylovcommented, May 25, 2020

I’ve made PR for solve this issue: https://github.com/facebook/react-native/pull/28956

It would be nice if some’ll have a look on it

0reactions
fabriziobertoglio1987commented, Feb 18, 2021

when you prepare a pr that solves an issue, you can connect it to the issue by including the following text in the pr summary

fixes https://github.com/facebook/react-native/issues/28953

this will automatically link the issue to the pr, once the pr is merged the issue will automatically be closed additionally a very useful icon shows in the issues list so other developers do not try to solve it

image

and also on top of the issue, it will show the linked pr so other developers do not troubleshooot that issue

image

more info https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue

thanks a lot for the pr 🙏 ☮️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: How to prevent any touch events from being passed ...
Add an onTouchEvent method to the view with top position then return true. True will tell the event bubbling that the event was...
Read more >
Track touch and pointer movements - Android Developers
This lesson describes how to track movement in touch events. ... (such as a swipe) and non-movement gestures (such as a single tap), ......
Read more >
Using Pointer Events - Web APIs | MDN
This guide demonstrates how to use pointer events and the HTML element to build a multi-touch enabled drawing application.
Read more >
Understanding Vue.js touch events for Android and iOS
They do not work on non-touchscreen devices. Unlike mouse events, which listen for interactions happening in the same instance, touch events can ...
Read more >
How touch events are delivered in Android - Suragch - Medium
If a View (or a ViewGroup) has an OnTouchListener , then the touch event is handled by OnTouchListener.onTouch() . Otherwise it is handled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found