react-native: Remote Debugger breaks onPress on Touchable Components

React Native version: 0.61.2

Steps To Reproduce

  1. Enable the remote debugger
  2. Tap a TouchableOpacity with onPress and onLongPress parameters
  3. Note that onLongPress is fired and not onPress even on short taps
  4. Works correctly if not in remote debugging

Describe what you expected to happen:

Upon a quick tap the component onLongPress fires, expected onPress to fire.

Minimal example

import React, { Component } from 'react';
import { Alert, Text, TouchableOpacity, View } from 'react-native';

class ExampleComponent extends Component<Props> {
  public render() {
    return (
      <View>
        <TouchableOpacity
          onPress={() => Alert.alert('Press')}
          onLongPress={() => Alert.alert('Long Press')}>
         <Text>Hello World</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

When in remote debugging onLongPress always fires.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 37
  • Comments: 60 (2 by maintainers)

Most upvoted comments

I believe I ended up tracking this down to an issue with there being a time difference between the host and device. Since the time is off, the calculation for whether it was a short press or long press is broken (or something like that). You can verify this by running adb shell "date" && date to see if the times are off. I think I was usually able to fix this by going into the device settings, disabling automatic time resolution, and then re-enabling it. I think there was also a way to do this via an adb command but can’t recall what it is.

I have 1 second difference that I can’t fix. And app doesn’t trigger onPress. Nice to see that this issue isn’t fixed from Oct 25.

@alexciarlillo You could have saved a lot more lives by recalling the adb command. Is it too much to ask for? 😦

Turning on/off Time date works only sometimes, and I don’t have rooted device, please react-native team look into this

Seriously, the development experience in React-Native is worst.

a few of us are experiencing this after an upgrade from 0.61 to 0.62. It would be great to have this addressed; it’s quite a major step backward not to be able to use the “improved” debugging mode on a physical device.

Unfortunately not all of our development devices are/can be rooted.

Thing is still not working for me, i ahve Huawei P20 i tried to disable/enebale automatic time in settings but problem is still there, my phone and mac have 2 sec diff.

Hey @HosseinRashno no need for that language. This is open source software. If it really bothers you so much, why don’t you fix it? We open issues to help resolve them, its a collective effort to fix it.

Also had a 2 sec difference. Disabling and enabling Automatic Date & Time didn’t resolve the issue. I set the time manually in the future in the hope it will process the events now, no success as well. However! Reenabling Automatic Date & Time after that might have forced it to pull a time back in sync with my development system. 🙌

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community’s attention? This issue may be closed if no further activity occurs. You may also label this issue as a “Discussion” or add it to the “Backlog” and I will leave it open. Thank you for your contributions.

@petergaultney @WouterFlorijn Agreed, relying on exact time sync between two systems seems like a pretty universally “bad idea”. @safaiyeh Do you know why this time sync is a requirement or know who to tag to get that answer? I think that’s probably the first step in figuring out the best solution for the issue.

To sync up time on Linux and OSX: adb shell su -c date "$(date +%m%d%H%M%Y.%S)".

This command requires a rooted phone.

Can confirm that the press is now working.

For android, i didn’t had a rooted phone. So instead i synced my host clock with phones clock.

It retrieves seconds and milliseconds since epoch, and sets it on the host. This is still problematic because 1- We should not need this kind of hack for debugging in the first place. 2- It will still introduce some difference in milliseconds due to execution time 3- We should instead use the same npt (time server)

sudo date +"%s.%N" -s @$(adb shell date +%s.%N)  

Then you can check the time difference between host and phone using as @evelant showed

echo "Host\t\t$(date +%Y-%m-%d_%H:%M:%S:%3N)" && echo "Emulator\t$(adb shell date +%Y-%m-%d_%H:%M:%S:%3N)" 

I used onPressIn() instead of onPress for now 😕

Still happening in my Android device. A real headache this problem is!

i’d agree (without much context for what the alternatives are, if any) that relying on timestamps being similar between two different computers for any functionality is a dangerous proposition.

@juanjsebgarcia I would say the only acceptable solution is to not rely on the times being synced. The debugger didn’t seem to rely on this earlier, as it has always worked fine for me without syncing device and host times. Having to sync the time is unreliable, as it can go out of sync at any moment. Whenever I managed to manually or automatically sync, it always stopped working again after only a few seconds.

I don’t seem to have permissions to add a label, but this is definitely still an active issue and should not be closed.

I believe that “timers” (setTimeout and setInterval) make this worse.

I use setInterval to countdown seconds and they go very fast. And when clicking to buttons we get the problem (no click).

Had same issue. Switching Automatic Date & Time off and on on my physical device didn’t fix this. I noticed the bug was on my emulator as well, so what I did was switch the automatic time on my machine (windows 10) off and on. It worked instantly!

This issue affects far more than just onPress. Set your clock to be slightly different than the device clock and observe things such as:

  • setInterval will fire immediately in an infinite loop or other broken behavior
  • Animation timing and delays will be off.
  • Animations will lag and run past their stop times.
  • Staggered animations will animate the first element to completion then animate the rest staggered as defined.
  • The app will randomly crash a lot
  • Occasionally all input will be ignored until the app is restarted
  • Pausing a breakpoint will crash/hang the app upon trying to resume
  • General performance will be unusable when debugging, 5-10x slower than dev mode and 20+x slower than release build. Many interactions simply don’t work or crash the app.
  • Profiling tools are unusable due to the poor performance (although there are many other issues with them as well this one renders them unusable)
  • react-devtools glitches out and loses connection

I’m pretty sure this has been an issue for a very long time, much longer than the Oct 2019 this issue was filed. I recall seeing this behavior at least 2 years ago.

Poor performance and stability when developing in the Android emulator is by far my team’s number one pain point with react-native (and it’s definitely RN not the emulator as Flutter dev experience is buttery smooth on the same emulated device). It seems this timing issue may be at the core of that problem so hopefully we can figure out what’s going on and improve the experience!

Edit: I did some digging and seem to have made the issue significantly better by syncing the clock of the android emulator and system. Here’s how:

  • You must have root access. This means a “google-apis” emulator image not a “google-play” one
  • Check the drift between your system and android clock with echo "Host\t\t$(date +%Y-%m-%d_%H:%M:%S:%3N)" && echo "Emulator\t$(adb shell date +%Y-%m-%d_%H:%M:%S:%3N)"
  • Sync the time (from a unix shell, I used git bash on windows) with adb root && adb shell date "$(date +%m%d%H%M%Y.%S%3N)"
  • Check time again, they should be in sync

After doing this things are (fingers crossed, for now) much smoother!

I believe I ended up tracking this down to an issue with there being a time difference between the host and device. Since the time is off, the calculation for whether it was a short press or long press is broken (or something like that). You can verify this by running adb shell "date" && date to see if the times are off. I think I was usually able to fix this by going into the device settings, disabling automatic time resolution, and then re-enabling it. I think there was also a way to do this via an adb command but can’t recall what it is.

Thanks!! This worked for me! 😃

me too

In my case, none of this worked and I don’t have a rooted device, so I ended up matching the time of phone and system manually. Apparently, accuracy upto milliseconds is not required, accuracy upto seconds is enough. So it worked that way. I have to do it everytime though and its really annoying.

I am seeing this on actual devices, Samsung S8 and intermittently on Pixel 2. If I tap many times very fast I can sometimes trigger the event on the Pixel 2, but it never fires on the S8.

edit: Both are running Android 9.