Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote Debugger breaks onPress on Touchable Components #27008

Closed
juanjsebgarcia opened this issue Oct 25, 2019 · 60 comments
Closed

Remote Debugger breaks onPress on Touchable Components #27008

juanjsebgarcia opened this issue Oct 25, 2019 · 60 comments
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@juanjsebgarcia
Copy link

juanjsebgarcia commented Oct 25, 2019

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.

@98ff98
Copy link

98ff98 commented Nov 15, 2019

I have same problem too

@alexciarlillo
Copy link

alexciarlillo commented Nov 19, 2019

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.

@stale
Copy link

stale bot commented Feb 17, 2020

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.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 17, 2020
@juanjsebgarcia
Copy link
Author

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

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 18, 2020
@chuanhaisoft
Copy link

same problem,onpress event not work,on android6

@alexciarlillo
Copy link

alexciarlillo commented Feb 27, 2020

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.

@juanjsebgarcia
Copy link
Author

Nice research @alexciarlillo. That definitely sounds plausible. Ideally this time sync would be something RN handles itself upon init.

I know if you spend too long at a breakpoint when using debugger and then resume it complains that the computer and device times have diverged. Perhaps a solution would be to have it sync times across both devices more often?

@Elias-Graf
Copy link

Elias-Graf commented Apr 15, 2020

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.

@Elias-Graf
Copy link

Elias-Graf commented Apr 20, 2020

@alexciarlillo Do you know why this occurs? Why are press events being processed on the package server and not the consumer? I just ran into this again and this is really annoying and takes a while until you realize that this is the issue (maybe anyone knows whom to bother with this? :D).

@alexciarlillo
Copy link

I'm not sure what the root cause is here, but when using remote debugging the code will always execute on the host machine, not the device itself. It's probably just mixup between the timestamp sent along with the native event not matching the actual time of the package server when it handles the event.

@Elias-Graf
Copy link

This is not just breaking onPress but also animation delays. See this SO post https://stackoverflow.com/questions/57178762/react-native-animated-delay-doesnt-respect-given-value/61652682#61652682

@juanjsebgarcia
Copy link
Author

I have weird issues with setInterval sometimes in debug mode too.

The interval in code is usually not the interval that is followed.

What usually happens in a transition that is meant to take say 2000ms, completes in 200ms. I usually just force stop the application (Android) and then restart it.

I wonder if this issue is related to the one being discussed here.

@Elias-Graf
Copy link

@juanjsebgarcia If you're experiencing this run echo "Host\t\t$(date +%Y-%m-%d_%H:%M:%S)" && echo "Emulator\t$(adb shell date +%Y-%m-%d_%H:%M:%S)" and compare the times, if their not synced up, you probably have the issue (Linux / Unix command only, if someone can make a windows version, that would be great [I tried but failed lol])

@kenobi91
Copy link

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.

@abhisheq6u
Copy link

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

@Elias-Graf
Copy link

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.

@abhisheq6u ...

@emacaste
Copy link

emacaste commented Jun 5, 2020

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.

It solves, thx... but what a craziness!

@petergaultney
Copy link

petergaultney commented Jun 5, 2020

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.

@Jlexyc
Copy link

Jlexyc commented Jun 10, 2020

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.

@bobsmits
Copy link

Same issue

@peetzweg
Copy link

peetzweg commented Jun 22, 2020

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. 🙌

@abhisheq6u
Copy link

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.

@hariantara
Copy link

hariantara commented Jun 30, 2020

Make sure you set the real device or emulator time as the same as your pc or laptop time until the seconds part should be the exactly the same.

I have tried it and it solved

@petergaultney
Copy link

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.

@evelant
Copy link

evelant commented Sep 4, 2020

@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.

@safaiyeh
Copy link
Contributor

safaiyeh commented Sep 6, 2020

I do not, I know you've had issues with this in another issue.

@shergin or @cpojer may know!

@SimonChaumet
Copy link

Still not fixed yet ?

@farhun
Copy link

farhun commented Nov 20, 2020

i have the same issue when i use firefox as debugger. Try use chrome as debugger, and when running your project try "npm start" then "npm run android/ios" . It solve my problem. Hope it solve yours too. Have a nice day everyone.

@varunraghu3112
Copy link

varunraghu3112 commented Nov 23, 2020

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.

Re-enabling and enabling the automatic time option works (NOTE: Internet must be turned on for sure else it won't work !)

@afilp
Copy link

afilp commented Dec 6, 2020

@varunraghu3112 I tried this and it worked sometimes (not always) do we also have to remove the cable from the device, so that we start adb reverse again? I mean, are there steps in a specific order to make this work? (when to turn off the internet, etc.). Thanks!

@verybluebot
Copy link

@alexciarlillo That was exactly my case! Would never thought about that thanks :)

@sanjeevyadavIT
Copy link

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.

@HosseinRashno
Copy link

HosseinRashno commented Jan 18, 2021

I have a Samsung Galaxy A50 phone. In some rare times, toggling the automatic update on and off is the trick that I need to sync the time but most of the time, it is not forcing the phone to sync the time with the NTP server.
After trying many things, I find out that I can force the date/time syncing by restarting the phone and it almost works every time.

@juanjsebgarcia
Copy link
Author

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.

@HosseinRashno
Copy link

HosseinRashno commented Jan 28, 2021

@juanjsebgarcia You're right. I've edited my comment and removed that part. I was just tired of spending a day fixing something that looks so simple!
Sorry for that 🙂

@Ong26
Copy link

Ong26 commented Feb 17, 2021

I have a Samsung Galaxy A50 phone. In some rare times, toggling the automatic update on and off is the trick that I need to sync the time but most of the time, it is not forcing the phone to sync the time with the NTP server.
After trying many things, I find out that I can force the date/time syncing by restarting the phone and it almost works every time.

This way also works for emulator devices!

@kg-currenxie
Copy link

kg-currenxie commented Mar 17, 2021

Same issue here, even on iOS (real device in debugging mode). So can't use adb :P

@ravindranpandu
Copy link

The only way to resolve this is to set your phone's time exactly equal to your laptop's timestamp, the time should be equal to seconds (milliseconds not counted).

@DJ-Icebear
Copy link

DJ-Icebear commented Mar 22, 2021

Have this issue as well with the remote debugger turned on, on both my physical Android and Iphone device. Attempting to sync the time on my devices & computer slightly alleviates the problem, but does not fix it.

@AnurajDev
Copy link

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

@afilp
Copy link

afilp commented Apr 23, 2021

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).

@Meltawab-lms
Copy link

I used onPressIn() instead of onPress for now :/

@withzhaoyu
Copy link

withzhaoyu commented May 15, 2021

meet same problem ,drive me crazy.. my solution:
(i use android emulator...
first, make sure enable your emulator network.
second,make sure enable automatic time resolution in SETTINGS - DATE & TIME
third , close your APP,and restart it.

@fredrivett
Copy link

I'm also experiencing this issue, but on iPhone 11 Pro, so running adb won't work for me. I've tried setting both clocks to strange times, and resetting them back plus restarting all debuggers, and nothing is getting the debugger to work here.

Makes debugging a real device near impossible.

Does anyone have any solutions that aren't android focussed?

@irfan798
Copy link

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)" 

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 25, 2023
@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Apr 1, 2023
@facebook facebook locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests