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

[Android] onResponderMove nativeEvent locationX does not change

Open erickreutz opened this issue 10 years ago • 28 comments

Hey guys,

Running into a bug (on Android only) where locationX of onResponderMove never changes as you drag along the view.

var MyComponent = React.createClass({
  onStartShouldSetResponder: function(e) {
    return true;
  },

  onMoveShouldSetResponder: function(e) {
    return true;
  },

  onResponderMove: function(e) {
    var evt = e.nativeEvent;
    console.log(evt.locationX);
  },

  render: function() {
    return (
      <View
        style={styles.box}
        onStartShouldSetResponder={this.onStartShouldSetResponder}
        onMoveShouldSetResponder={this.onMoveShouldSetResponder}
        onResponderMove={this.onResponderMove}>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  box: {
    flexDirection: 'row',
    alignSelf: 'center',
    width: 200,
    height: 50,
    backgroundColor: 'red'
  }
});

React Native 0.22.0 OSX

erickreutz avatar Apr 25 '16 22:04 erickreutz

@facebook-github-bot bugfix

christopherdro avatar Apr 27 '16 03:04 christopherdro

Confirming this is a bug. Took time last night to dig in and narrowed the problem down to these 2 lines. For some reasons the subtraction of the 2 floats only happens on first touch and not during the entire interaction. What's strange is console logging those two values separately shows that both update throughout the entire touch interaction.

Will look into it a bit more.

/cc @dmmiller Thoughts?

Example https://rnplay.org/apps/i0rjeQ

christopherdro avatar Apr 27 '16 03:04 christopherdro

Hey @erickreutz, we're a small team and rely on the community to fix issues that don't affect fb apps. If you're sure this is a bug can you send a pull request with a fix?

ghost avatar Apr 27 '16 03:04 ghost

This is a bug. I have an internal bug to fix it but haven't gotten to it yet. If you'd like to send a pull request to fix it, I'm happy to check it out.

dmmiller avatar Apr 27 '16 08:04 dmmiller

@dmmiller Whats the issue?

christopherdro avatar Apr 27 '16 15:04 christopherdro

We just haven't fixed it. I just mean to let you know that I know about it.

dmmiller avatar Apr 27 '16 15:04 dmmiller

Ah I see, I thought you might of known what was causing that bug.

christopherdro avatar Apr 27 '16 15:04 christopherdro

Honestly, I haven't looked into it yet. Too many other things to look at. If you want to dive in and see, that would be great :)

dmmiller avatar Apr 27 '16 15:04 dmmiller

What's happening is the the two values you are trying to subtract to get locationX and locationY both increment/decrement in parallel so the subtracted value is always going to be the same.

christopherdro avatar Apr 27 '16 15:04 christopherdro

Not sure if I'll have the time to send a PR for this one. As a work around I've just been calculating my own locationX with pageX minus the x origin of the target view.

erickreutz avatar Apr 29 '16 08:04 erickreutz

Was this ever able to be fixed? My hack is broken now onLayout has the x origin of the view as 0 in the 0.28

erickreutz avatar Jul 15 '16 22:07 erickreutz

So sad. We encountered the same issue in 0.29 version.

YongX avatar Jul 21 '16 07:07 YongX

Still seeing in 0.30.0.

eremzeit avatar Sep 01 '16 01:09 eremzeit

@erickreutz

onLayout is returning the page offset correctly for me as of 0.30.0 so I'm able to use your hack to work.

eremzeit avatar Sep 01 '16 01:09 eremzeit

confirm this is still happening in 0.32.1

following code is sufficient to reproduce it:

      <View
        onTouchMove={(e) => {console.log('touchMove', e.nativeEvent)}}
        style={{flex: 1}}
       />

chunghe avatar Sep 09 '16 07:09 chunghe

Can confirm, happening on 0.33.0.

robclouth avatar Sep 16 '16 14:09 robclouth

Still seeing in 0.35.0

leecade avatar Oct 13 '16 20:10 leecade

the trouble is that in float targetViewCoordinateX = motionEvent.getX() - event.getViewX();

the motionEvent.getX() changes (when dragging) while event.getViewX() stays the same and denotes when the touch started. These coordinates are assigned once and continue to be passed here.

vonovak avatar Dec 12 '16 22:12 vonovak

Still seeing this on 0.40

robclouth avatar Jan 13 '17 11:01 robclouth

Still exists on 0.41.2. any plan to fix it ?

richmonkey avatar Feb 24 '17 07:02 richmonkey