react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Touches] Translated components receive touches at their non-translated position

Open ide opened this issue 11 years ago • 21 comments

When translating a View on Android (0.14.0-dev), it continues to receive touches at its original position which is probably not what you want. Here's the repro with PanResponderExample in the UIExplorer (you need to touch the top-left of the scene to move the circle):

diff --git a/Examples/UIExplorer/PanResponderExample.js b/Examples/UIExplorer/PanResponderExample.js
index c2e6a66..f469439 100644
--- a/Examples/UIExplorer/PanResponderExample.js
+++ b/Examples/UIExplorer/PanResponderExample.js
@@ -53,8 +53,10 @@ var PanResponderExample = React.createClass({
     this._previousTop = 84;
     this._circleStyles = {
       style: {
-        left: this._previousLeft,
-        top: this._previousTop
+        transform: [
+          { translateY: this._previousTop },
+          { translateX: this._previousLeft },
+        ],
       }
     };
   },
@@ -112,8 +114,10 @@ var PanResponderExample = React.createClass({
     this._highlight();
   },
   _handlePanResponderMove: function(e: Object, gestureState: Object) {
-    this._circleStyles.style.left = this._previousLeft + gestureState.dx;
-    this._circleStyles.style.top = this._previousTop + gestureState.dy;
+    this._circleStyles.style.transform = [
+      { translateY: this._previousTop + gestureState.dy },
+      { translateX: this._previousLeft + gestureState.dx },
+    ];
     this._updatePosition();
   },
   _handlePanResponderEnd: function(e: Object, gestureState: Object) {

ide avatar Oct 21 '15 01:10 ide

cc @mkonicek @kmagiera is this simply how Android behaves? I can use absolute positioning instead, but if it's possible for RN to fix this in a nice way, that would be great too.

ide avatar Oct 21 '15 02:10 ide

Ah @ide is this basically the reason for https://github.com/exponentjs/react-native-invertible-scroll-view/issues/16?

PhilippKrone avatar Oct 31 '15 21:10 PhilippKrone

Yeah I think so. It might just be Android clowniness but perhaps RN is doing something to disable hitbox translation or can change this behavior on Android.

ide avatar Oct 31 '15 23:10 ide

Interesting, thanks for reporting it. @andreicoman11 do you think it's related to the issue where touch coordinates are absolute instead of relative on Android?

mkonicek avatar Nov 06 '15 13:11 mkonicek

This regression was introduced in https://github.com/facebook/react-native/commit/c805157cac6acbb74690f209fe7bfd9ea51f8e55

satya164 avatar Nov 16 '15 13:11 satya164

@dmmiller Is now working on making the payload of touch events consistent between iOS and Android.

mkonicek avatar Nov 17 '15 16:11 mkonicek

@dmmiller thanks a lot! :)

PhilippKrone avatar Nov 17 '15 16:11 PhilippKrone

@dmmiller Sorry to ask again, but is there any ETA on this? Or any hotfix I could test?

PhilippKrone avatar Nov 19 '15 06:11 PhilippKrone

@PhilippKrone Currently I've reverted the commit I've linked to and building from source. I needed to use adjustResize for the keyboard since reverting the commit re-surfaces the bug where touch points will be wrong if view is moved up due to keyboard focus. Really waiting for the fix.

satya164 avatar Nov 23 '15 00:11 satya164

@satya164 OK, I understand. I'm currently checking whether the following PR by @dmmiller might fix this issue: https://github.com/facebook/react-native/commit/0c2ee5d480e696f8621252c936a8773e8de9f8b6, but it seems not to. :(

PhilippKrone avatar Nov 24 '15 19:11 PhilippKrone

I've now implemented this fix but the issue is not gone yet.

PhilippKrone avatar Nov 25 '15 11:11 PhilippKrone

@PhilippKrone Which fix?

satya164 avatar Nov 25 '15 11:11 satya164

@satya164 Sorry, I guess the message didnt come through: https://github.com/facebook/react-native/commit/0c2ee5d480e696f8621252c936a8773e8de9f8b6

PhilippKrone avatar Nov 25 '15 11:11 PhilippKrone

I have a fix internally that I should be pushing in the next day or so.

dmmiller avatar Nov 25 '15 16:11 dmmiller

@dmmiller thanks for the update. Much appreciated I'm sure.

ide avatar Nov 25 '15 17:11 ide

@PhilippKrone @satya164 That fix you mentioned was not a fix for this issue. That fix fixed the values passed in the touch events to be local to the targeted view. The fix for this is currently in review and is explicitly for transformed views.

dmmiller avatar Nov 25 '15 17:11 dmmiller

@dmmiller Looking forward to the fix. Thanks a lot :)

satya164 avatar Nov 26 '15 00:11 satya164

@dmmiller Would be totally awesome if we could get it to 0.16.0 #4327

satya164 avatar Nov 27 '15 01:11 satya164

@dmmiller Anything new concerning this fix for transformed views?

PhilippKrone avatar Nov 28 '15 09:11 PhilippKrone

Waiting on @andreicoman11 to get back from holiday and accept it :) He should be back today so hopefully, we can get it pushed today.

dmmiller avatar Nov 30 '15 09:11 dmmiller